当前位置: 首页>>代码示例>>C#>>正文


C# StringBuilder.LastIndexOf方法代码示例

本文整理汇总了C#中System.Text.StringBuilder.LastIndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.LastIndexOf方法的具体用法?C# StringBuilder.LastIndexOf怎么用?C# StringBuilder.LastIndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.StringBuilder的用法示例。


在下文中一共展示了StringBuilder.LastIndexOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Process

        public void Process(
            XmlReader xmlReader, 
            StringBuilder output,
            ElementProcessContext elementProcessContext)
        {
            if (elementProcessContext.Current.IsPreservingSpace)
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            else if (elementProcessContext.Current.IsSignificantWhiteSpace && !output.IsNewLine())
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            else if ((elementProcessContext.Current.ContentType == ContentTypeEnum.None)
                && this.options.RemoveEndingTagOfEmptyElement)
            {
                // Shrink the current element, if it has no content.
                // E.g., <Element>  </Element> => <Element />
                output = output.TrimEnd(' ', '\t', '\r', '\n');

                int bracketIndex = output.LastIndexOf('>');
                output.Insert(bracketIndex, '/');

                if ((output[bracketIndex - 1] != '\t') 
                    && (output[bracketIndex - 1] != ' ')
                    && this.options.SpaceBeforeClosingSlash)
                {
                    output.Insert(bracketIndex, ' ');
                }
            }
            else if ((elementProcessContext.Current.ContentType == ContentTypeEnum.SingleLineTextOnly)
                && !elementProcessContext.Current.IsMultlineStartTag)
            {
                int bracketIndex = output.LastIndexOf('>');

                string text = output.Substring((bracketIndex + 1), (output.Length - bracketIndex - 1)).Trim();

                output.Length = (bracketIndex + 1);
                output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
            }
            else
            {
                string currentIndentString = this.indentService.GetIndentString(xmlReader.Depth);

                if (!output.IsNewLine())
                {
                    output.Append(Environment.NewLine);
                }

                output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
            }

            elementProcessContext.Pop();
        }
开发者ID:tmatz,项目名称:XamlStyler,代码行数:54,代码来源:EndElementDocumentProcessor.cs

示例2: Process

        public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessContext elementProcessContext)
        {
            if (elementProcessContext.Current.IsPreservingSpace)
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            else if (elementProcessContext.Current.IsSignificantWhiteSpace && !output.IsNewLine())
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            // Shrink the current element, if it has no content.
            // E.g., <Element>  </Element> => <Element />
            else if (elementProcessContext.Current.ContentType == ContentTypeEnum.NONE && _options.RemoveEndingTagOfEmptyElement)
            {
                #region shrink element with no content

                output = output.TrimEnd(' ', '\t', '\r', '\n');

                int bracketIndex = output.LastIndexOf('>');
                output.Insert(bracketIndex, '/');

                if (output[bracketIndex - 1] != '\t' && output[bracketIndex - 1] != ' ' && _options.SpaceBeforeClosingSlash)
                {
                    output.Insert(bracketIndex, ' ');
                }

                #endregion shrink element with no content
            }
            else if (elementProcessContext.Current.ContentType == ContentTypeEnum.SINGLE_LINE_TEXT_ONLY && elementProcessContext.Current.IsMultlineStartTag == false)
            {
                int bracketIndex = output.LastIndexOf('>');

                string text = output.Substring(bracketIndex + 1, output.Length - bracketIndex - 1).Trim();

                output.Length = bracketIndex + 1;
                output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
            }
            else
            {
                string currentIndentString = _indentService.GetIndentString(xmlReader.Depth);

                if (!output.IsNewLine())
                {
                    output.Append(Environment.NewLine);
                }

                output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
            }

            elementProcessContext.Pop();
        }
开发者ID:NicoVermeir,项目名称:XamlStyler,代码行数:51,代码来源:EndElementDocumentProcessor.cs

示例3: GetContent

        public static string GetContent(ApiRequest request, string configuration, TransformalizeResponse response) {

            var content = string.Empty;
            var results = string.Empty;
            var builder = new StringBuilder();
            var processes = string.Empty;

            switch (request.RequestType) {
                case ApiRequestType.MetaData:
                    builder.Append(configuration);
                    builder.InsertFormat(builder.LastIndexOf('<'), RESPONSE_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, LogsToXml(response.Log), content);
                    return builder.ToString();

                case ApiRequestType.Configuration:
                    builder.Append(configuration);
                    builder.InsertFormat(builder.LastIndexOf('<'), MINIMAL_RESPONSE_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds);
                    return builder.ToString();

                case ApiRequestType.Enqueue:
                    builder.AppendFormat(XML_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, processes, results, LogsToXml(response.Log), content);
                    return builder.ToString();

                case ApiRequestType.Execute:

                    switch (request.Flavor) {
                        case "attributes":
                            processes = SecureConfiguration(configuration);
                            results = new XmlResultsToAttributesHandler().Handle(response.Processes);
                            break;
                        case "table":
                            content = new XmlResultsToHtmlTable().Handle(response.Processes);
                            break;
                        default:
                            processes = SecureConfiguration(configuration);
                            results = new XmlResultsToDictionaryHandler().Handle(response.Processes);
                            break;
                    }
                    builder.AppendFormat(XML_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, processes, results, LogsToXml(response.Log), content);
                    return builder.ToString();

                default:
                    if (request.Status == 200) {
                        request.Status = 400;
                        request.Message = "Bad Request";
                    }
                    builder.AppendFormat(XML_TEMPLATE, request.RequestType, request.Status, request.Message, request.Stopwatch.ElapsedMilliseconds, string.Empty, processes, results, LogsToXml(response.Log), content);
                    return builder.ToString();
            }

        }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:50,代码来源:XmlContentHandler.cs

示例4: ExtensionMethods_LastIndexOf_WhenNormalStringWithCaseIgnore_ExpectLastIndex

        public void ExtensionMethods_LastIndexOf_WhenNormalStringWithCaseIgnore_ExpectLastIndex()
        {
            //------------Setup for test--------------------------
            StringBuilder value = new StringBuilder("aaa bbb aaa ccc ddd aaa eee BBB");

            //------------Execute Test---------------------------
            var result = value.LastIndexOf("bbb", true);

            //------------Assert Results-------------------------
            Assert.AreEqual(28, result);
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:11,代码来源:ExtensionMethodsTest.cs

示例5: ProcessEndElement

        private void ProcessEndElement(XmlReader xmlReader, StringBuilder output)
        {
            if (this.ElementProcessStatusStack.Peek().IsPreservingSpace)
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            else if (this.ElementProcessStatusStack.Peek().IsSignificantWhiteSpace && !output.IsNewLine())
            {
                output.Append("</").Append(xmlReader.Name).Append(">");
            }
            // Shrink the current element, if it has no content.
            // E.g., <Element>  </Element> => <Element />
            else if ((ContentTypeEnum.None == this.ElementProcessStatusStack.Peek().ContentType)
                && Options.RemoveEndingTagOfEmptyElement)
            {
                #region shrink element with no content

                output = output.TrimEnd(' ', '\t', '\r', '\n');

                int bracketIndex = output.LastIndexOf('>');
                output.Insert(bracketIndex, '/');

                if ((output[bracketIndex - 1] != '\t')
                    && (output[bracketIndex - 1] != ' ')
                    && Options.SpaceBeforeClosingSlash)
                {
                    output.Insert(bracketIndex, ' ');
                }

                #endregion shrink element with no content
            }
            else if ((ContentTypeEnum.SingleLineTextOnly == this.ElementProcessStatusStack.Peek().ContentType)
                && !this.ElementProcessStatusStack.Peek().IsMultlineStartTag)
            {
                int bracketIndex = output.LastIndexOf('>');

                string text = output.Substring(bracketIndex + 1, output.Length - bracketIndex - 1).Trim();

                output.Length = bracketIndex + 1;
                output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
            }
            else
            {
                string currentIndentString = this.GetIndentString(xmlReader.Depth);

                if (!output.IsNewLine())
                {
                    output.Append(Environment.NewLine);
                }

                output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
            }
        }
开发者ID:jlaanstra,项目名称:XamlMagic,代码行数:53,代码来源:StylerService.cs

示例6: ProcessEndElement

        private void ProcessEndElement(XmlReader xmlReader, StringBuilder output)
        {
            // Shrink the current element, if it has no content.
            // E.g., <Element>  </Element> => <Element />
            if (ContentTypeEnum.NONE == _elementProcessStatusStack.Peek().ContentType
                && Options.RemoveEndingTagOfEmptyElement)
            {
                #region shrink element with no content

                output = output.TrimEnd(' ', '\t', '\r', '\n');

                int bracketIndex = output.LastIndexOf('>');
                output.Insert(bracketIndex, '/');

                if (output[bracketIndex - 1] != '\t' && output[bracketIndex - 1] != ' ' && Options.SpaceBeforeClosingSlash)
                {
                    output.Insert(bracketIndex, ' ');
                }

                #endregion shrink element with no content
            }
            else if (ContentTypeEnum.SINGLE_LINE_TEXT_ONLY == _elementProcessStatusStack.Peek().ContentType
                     && false == _elementProcessStatusStack.Peek().IsMultlineStartTag)
            {
                int bracketIndex = output.LastIndexOf('>');

                string text = output.Substring(bracketIndex + 1, output.Length - bracketIndex - 1).Trim();

                output.Length = bracketIndex + 1;
                output.Append(text).Append("</").Append(xmlReader.Name).Append(">");
            }
            else
            {
                string currentIndentString = GetIndentString(xmlReader.Depth);

                if (!output.IsNewLine())
                {
                    output.Append(Environment.NewLine);
                }

                output.Append(currentIndentString).Append("</").Append(xmlReader.Name).Append(">");
            }
        }
开发者ID:sh4nji,项目名称:XamlStyler,代码行数:43,代码来源:StylerService.cs

示例7: GenerateCode


//.........这里部分代码省略.........
            ICodeBlock destroySection = CodeWriter.GenerateDestroy(element);
            int startOfDestroySection = CodeWriter.GetIndexAfter("// Generated Destroy", stringBuilder);
            stringBuilder.Insert(startOfDestroySection, destroySection.ToString());

            #endregion


            #region Generate Methods

            ICodeBlock methodsSection = new CodeDocument(2);

            CodeWriter.GenerateMethods(methodsSection, element);

            int startOfMethodsSection = CodeWriter.GetIndexAfter("// Generated Methods", stringBuilder);
            stringBuilder.Insert(startOfMethodsSection, methodsSection.ToString());

            #endregion


            #region Extra Classes
            CodeBlockBase codeBlock = new CodeBlockBase(null);

            foreach (var codeGenerator in CodeGenerators)
            {
                codeGenerator.GenerateAdditionalClasses(codeBlock, element);
            }


            string extraClasses = codeBlock.ToString();

            if (!string.IsNullOrEmpty(extraClasses))
            {
                const string extraClassesComment = "// Extra classes";
                int indexToReplace = stringBuilder.LastIndexOf(extraClassesComment);

                stringBuilder.Remove(indexToReplace, extraClassesComment.Length);

                stringBuilder.Insert(indexToReplace, extraClasses);

            }
            #endregion

            string generatedCodeFileName = element.Name + ".Generated.cs";



            CodeWriter.SaveFileContents(stringBuilder.ToString(), FileManager.RelativeDirectory + generatedCodeFileName, true);


            #region Extra stuff if it's a ScreenSave

            if (element is ScreenSave)
            {
                bool inherits = !string.IsNullOrEmpty(element.BaseElement) && element.BaseElement != "<NONE>";
                if (inherits)
                {
                    #region Set the inheritance to the proper class

                    string fileContents;
                    string nameWithoutPath = FileManager.RemovePath(element.Name);

                    fileContents = FileManager.FromFileText(FileManager.RelativeDirectory + element.Name + ".Generated.cs");

                    #endregion

                    #region Replace the ContentManagerName
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:67,代码来源:CodeWriter.cs

示例8: Connect

		/// <summary>
		/// To connect to the server.
		/// </summary>
		public void Connect()
		{
			_logReceiver.AddInfoLog("[{0}] Connecting...", Name);

			if (_socket != null)
				throw new InvalidOperationException(LocalizedStrings.Str2152);

			_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

			try
			{
				_socket.Connect(Address);

				lock (_syncDisconnect)
					IsExportStarted = true;

				ThreadingHelper
					.Thread(() =>
					{
						var buf = new StringBuilder();
						var buffer = new byte[1024];
						var isError = false;

						try
						{
							while (true)
							{
								if (_socket == null)
									throw new InvalidOperationException(LocalizedStrings.Str2153);

								if (_socket.Poll(500000, SelectMode.SelectRead))
								{
									// http://stackoverflow.com/questions/2661764/how-to-check-if-a-socket-is-connected-disconnected-in-c
									if (_socket.Available == 0)
										throw new InvalidOperationException(LocalizedStrings.Str1611);

									var bytesRecv = _socket.Receive(buffer, 0, buffer.Length, SocketFlags.None);

									buf.Append(Encoding.ASCII.GetString(buffer, 0, bytesRecv));

									var index = buf.LastIndexOf('\n');

									if (index == -1)
										continue;

									var res = buf.ToString(0, index + 1);
									var reply = res.Split("\n").Select(v => v.TrimEnd('\r', '\n'));

									if (index < buf.Length - 1)
										buf.Remove(0, index + 1);
									else
										buf.Clear();

									try
									{
										foreach (var line in reply)
										{
											_logReceiver.AddDebugLog("[{0}] Response: {1}", Name, line);
											ProcessReply.SafeInvoke(line);
										}
									}
									catch (Exception ex)
									{
										_logReceiver.AddErrorLog(ex);
									}
								}

								lock (_syncDisconnect)
								{
									if (IsExportStarted)
										continue;

									_logReceiver.AddInfoLog(LocalizedStrings.Str2154Params, Name);
									Monitor.Pulse(_syncDisconnect);
									break;
								}
							}
						}
						catch (ObjectDisposedException ex)
						{
							isError = true;
							ConnectionError.SafeInvoke(new InvalidOperationException(LocalizedStrings.Str2155, ex));
						}
						catch (Exception ex)
						{
							isError = true;
							ConnectionError.SafeInvoke(ex);
						}

						if (isError)
						{
							lock (_syncDisconnect)
								IsExportStarted = false;	
						}

						try
						{
//.........这里部分代码省略.........
开发者ID:hbwjz,项目名称:StockSharp,代码行数:101,代码来源:IQFeedWrapper.cs

示例9: TestInsertAt

 public void TestInsertAt() {
     var sb = new StringBuilder("<strong>emphasis</strong>");
     var index = sb.LastIndexOf('<');
     sb.Insert(index, "!!!");
     Assert.AreEqual("<strong>emphasis!!!</strong>", sb.ToString());
 }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:6,代码来源:TestStringBuilderExtensions.cs

示例10: TestInsertFormat

 public void TestInsertFormat()
 {
     var sb = new StringBuilder("<strong>emphasis</strong>");
     sb.InsertFormat(sb.LastIndexOf('<')," and other {0}.", "things");
     Assert.AreEqual("<strong>emphasis and other things.</strong>", sb.ToString());
 }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:6,代码来源:TestStringBuilderExtensions.cs

示例11: TestLastIndexOfNotThere

 public void TestLastIndexOfNotThere() {
     var sb = new StringBuilder("<strong>emphasis</strong>");
     Assert.AreEqual(-1, sb.LastIndexOf('!'));
 }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:4,代码来源:TestStringBuilderExtensions.cs

示例12: TestLastIndexOf

 public void TestLastIndexOf() {
     var sb = new StringBuilder("<strong>emphasis</strong>");
     Assert.AreEqual(16, sb.LastIndexOf('<'));
 }
开发者ID:modulexcite,项目名称:Transformalize,代码行数:4,代码来源:TestStringBuilderExtensions.cs

示例13: IndexTest

 public void IndexTest()
 {
     StringBuilder str = new StringBuilder("Hello");
     Assert.AreEqual(1, str.IndexOf("el"));
     Assert.AreEqual(3, str.LastIndexOf("l"));
 }
开发者ID:rexzh,项目名称:RexToy,代码行数:6,代码来源:StringBuilderExtTest.cs

示例14: ClearComments

        public static string ClearComments(this string html)
        {
            html = html.CleanHeader();

            var starts = new List<int>();
            for (var i = 0; i < html.Length; i++)
            {
                if (i >= html.Length - 4)
                {
                    break;
                }

                i = html.IndexOf(@"<!--", i, StringComparison.Ordinal);
                if (i == -1)
                {
                    break;
                }
                starts.Add(i);
            }

            var ends = starts.Select(start => html.IndexOf(@"-->", start, StringComparison.Ordinal) + 3).ToList();

            var content = new StringBuilder(html).ToString(); 
            //Enable cleaning mso styling
            content = starts.Select((t, i) => html.Substring(t, ends[i] - t)).Aggregate(content, (current, comment) => current.Replace(comment, ""));

            content = content.Replace(@"<![if !vml]>", "");
            content = content.Replace(@"<![endif]>", "");




            content = content.Substring(content.IndexOf("<body"));
            content = content.Substring(content.IndexOf(">") + 1);
            content = content.Remove(content.LastIndexOf("</body>"), content.Length - content.LastIndexOf("</body>"));


            //deleting index from description
            if (content.Contains("<div style='mso-element:comment-list'>"))
            {
                content = content.Remove(content.IndexOf("<div style='mso-element:comment-list'>"));
            }

            for (int i = 0; ; i++)
            {
                if (!content.Contains(">["))
                {
                    break;
                }
                //content = content.Remove(content.IndexOf(">[")+1, 5);
                content = content.Remove(content.IndexOf(">[") + 1, (content.IndexOf("]</a>")+1) - (content.IndexOf(">[") + 1));
            }
            return content.Trim();

        }
开发者ID:nkravch,项目名称:SALMA-2.0,代码行数:55,代码来源:MarkupConverter.cs

示例15: ExtensionMethods_LastIndexOf_WhenNormalStringInMiddle_ExpectLastIndex

        public void ExtensionMethods_LastIndexOf_WhenNormalStringInMiddle_ExpectLastIndex()
        {
            //------------Setup for test--------------------------
            StringBuilder value = new StringBuilder("aaa bbb aaa ccc ddd aaa eee bbb");

            //------------Execute Test---------------------------
            var result = value.LastIndexOf("ccc", false);

            //------------Assert Results-------------------------
            Assert.AreEqual(12, result);
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:11,代码来源:ExtensionMethodsTest.cs


注:本文中的System.Text.StringBuilder.LastIndexOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。