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


C# StringBuilder.Contains方法代码示例

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


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

示例1: Combining_Multiple_Files

        public void Combining_Multiple_Files()
        {
            var cr = new ContentResolver { ContentDir = FileSets() };

            var paths = new List<string>
            {
                "~/Multiple_File_Set/Single-File-0.js",
                "~/Multiple_File_Set/Single-File-1.js",
                "~/Multiple_File_Set/Single-File-2.js",
                "~/Multiple_File_Set/Single-File-3.js"
            };

            var buff = new StringBuilder().CombineContents(paths, cr).ToString();

            var names = paths.Select(p => Path.GetFileName(p));

            Expect(names.All(name => buff.Contains(name)));
        }
开发者ID:lcaballero,项目名称:LucidEdge,代码行数:18,代码来源:Test_Combining_Files.cs

示例2: CleanString

        /// <summary>
        /// подготавливает строку к хешированию
        /// </summary>
        /// <param name="data">входной набор символов</param>
        /// <returns>StringBuilder or null</returns>
        private StringBuilder CleanString(string data)
        {
            if (string.IsNullOrEmpty(data)) return null;

            HtmlParser parser = new HtmlParser();
            var result = new StringBuilder(data.ToLower());
            parser.ClearContent(result);
            for (int i = 0; i < this.keywords.Length; i++)
            {
                if (this.keywords[i] != "")
                {
                    while (result.Contains(this.keywords[i]) >= 0)
                        result.Replace(this.keywords[i], string.Empty);
                }
            }
            parser.ClearContent(result);//еще раз зачищаем строку
            return result;
        }
开发者ID:MaxIakovliev,项目名称:asp.net-mvc-real-estate,代码行数:23,代码来源:Cleaner.cs

示例3: SetEnvironment

 private void SetEnvironment()
 {
   StringBuilder current = new StringBuilder(Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine));
   if (!current.Contains(FolderPath))
   {
     // Folder path always ends with \
     if (current[current.Length - 1] != ';')
       current.Append(';');
     current.Append(FolderPath);
     Environment.SetEnvironmentVariable("Path", current.ToString(), EnvironmentVariableTarget.Machine);
   }
 }
开发者ID:Gazzilow,项目名称:ffmpeg-vp9-wrap,代码行数:12,代码来源:FfmpegLoader.cs

示例4: ProcessTemplate

        /// <summary>
        /// constructor, open template from file
        /// </summary>
        /// <param name="AFullPath"></param>
        public ProcessTemplate(string AFullPath = null)
        {
            if ((AFullPath == null) || (AFullPath.Length == 0))
            {
                return;
            }

            if (!File.Exists(AFullPath))
            {
                throw new Exception("Cannot find template file " + AFullPath + "; please adjust the TemplateDir parameter");
            }

            StreamReader r;
            r = File.OpenText(AFullPath);
            FTemplateCode = new StringBuilder();

            while (!r.EndOfStream)
            {
                string line = r.ReadLine().TrimEnd(new char[] { '\r', '\t', ' ', '\n' }).Replace("\t", "    ");
                FTemplateCode.Append(line).Append(Environment.NewLine);
            }

            r.Close();

            // add other files, {#INCLUDE <filename>}
            while (FTemplateCode.Contains("{#INCLUDE "))
            {
                Int32 pos = FTemplateCode.IndexOf("{#INCLUDE ");
                Int32 newLinePos = FTemplateCode.IndexOf(Environment.NewLine, pos);
                string line = FTemplateCode.Substring(pos, newLinePos - pos);
                Int32 bracketClosePos = FTemplateCode.IndexOf("}", pos);
                string filename = FTemplateCode.Substring(pos + "{#INCLUDE ".Length, bracketClosePos - pos - "{#INCLUDE ".Length).Trim();

                // do this recursively, to get snippets and code in the right place, even from the include files
                ProcessTemplate includedTemplate = new ProcessTemplate(Path.GetDirectoryName(AFullPath) + Path.DirectorySeparatorChar + filename);

                FTemplateCode = FTemplateCode.Replace(line, includedTemplate.FTemplateCode.ToString());

                foreach (string key in includedTemplate.FSnippets.Keys)
                {
                    FSnippets.Add(key, includedTemplate.FSnippets[key]);
                }
            }

            // split off snippets (identified by "{##")
            if (FTemplateCode.Contains("{##"))
            {
                StringCollection snippets = StringHelper.StrSplit(FTemplateCode.ToString(), "{##");

                // first part is the actual template code
                FTemplateCode = new StringBuilder(snippets[0]);

                for (int counter = 1; counter < snippets.Count; counter++)
                {
                    string snippetName = snippets[counter].Substring(0, snippets[counter].IndexOf("}"));

                    // exclude first newline
                    string snippetText = snippets[counter].Substring(snippets[counter].IndexOf(Environment.NewLine) + Environment.NewLine.Length);

                    // remove all whitespaces from the end, but keep one line ending for ENDIF etc
                    snippetText = snippetText.TrimEnd(new char[] { '\n', '\r', ' ', '\t' }) + Environment.NewLine;
                    FSnippets.Add(snippetName, snippetText);
                }
            }

            // just make sure that there is a newline at the end, for ENDIF etc
            FTemplateCode.Append(Environment.NewLine);
        }
开发者ID:Davincier,项目名称:openpetra,代码行数:72,代码来源:ProcessTemplate.cs

示例5: ExtensionMethods_Contains_WhenSubstringIsNotContained_ExpectFalse

        public void ExtensionMethods_Contains_WhenSubstringIsNotContained_ExpectFalse()
        {
            //------------Setup for test--------------------------
            StringBuilder value = new StringBuilder("a b c");

            //------------Execute Test---------------------------
            var result = value.Contains(" bq");

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

示例6: Contains_SubStringInMiddle

		public void Contains_SubStringInMiddle()
		{
			StringBuilder builder = new StringBuilder();
			builder.Append("bcdef");
			string subString = "cde";
			bool doesContain = builder.Contains(subString);
			Assert.IsTrue(doesContain);
		}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:8,代码来源:StringBuilderExtensionsTests.cs

示例7: Contains_SubStringOverlapsEnd

		public void Contains_SubStringOverlapsEnd()
		{
			StringBuilder builder = new StringBuilder();
			builder.Append("bcdef");
			string subString = "efg";
			bool doesContain = builder.Contains(subString);
			Assert.IsFalse(doesContain);
		}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:8,代码来源:StringBuilderExtensionsTests.cs

示例8: Contains_StringsAreNonAscii

		public void Contains_StringsAreNonAscii()
		{
			StringBuilder builder = new StringBuilder();

			//Some random japanese characters, not a perfect test I know but it shows
			//that the function works with non ascii characters.
			builder.Append("\u3041\u3042\u3043");
			string subString = "\u3042";
			bool doesContain = builder.Contains(subString);
			Assert.IsTrue(doesContain);
		}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:11,代码来源:StringBuilderExtensionsTests.cs

示例9: Contains_SubStringDiffersInCaseOnly

		public void Contains_SubStringDiffersInCaseOnly()
		{
			StringBuilder builder = new StringBuilder();
			builder.Append("abcdefg");
			string subString = "CDE";
			bool doesContain = builder.Contains(subString);
			Assert.IsFalse(doesContain);
		}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:8,代码来源:StringBuilderExtensionsTests.cs

示例10: Contains_SubStringEmpty

		public void Contains_SubStringEmpty()
		{
			StringBuilder builder = new StringBuilder();
			string subString = null;
			bool doesContain = builder.Contains(subString);
			Assert.IsFalse(doesContain);
		}
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:7,代码来源:StringBuilderExtensionsTests.cs

示例11: GenerateUsings

        internal static void GenerateUsings(StringBuilder stringBuilder, IElement saveObject)
        {
            if (stringBuilder.Contains("// Generated Usings"))
            {
                ICodeBlock usings = new CodeDocument();

                UsingsCodeGenerator.GenerateUsingStatements(usings, saveObject);

                int startOfUsingSection = GetIndexAfter("// Generated Usings", stringBuilder);
                stringBuilder.Insert(startOfUsingSection, usings.ToString());
            }
        }
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:12,代码来源:CodeWriter.cs

示例12: GenerateCode


//.........这里部分代码省略.........
                    relativeDirectory = relativeDirectory.Replace('/', '.');

                    projectNamespace += "." + relativeDirectory;
                }
            }
            else if (element is ScreenSave)
            {
                projectNamespace += ".Screens";
            }

            string contentManagerName = element.UseGlobalContent ? "\"Global\"" : null;
            ScreenSave asScreenSave = element as ScreenSave;
            if (asScreenSave != null &&
                !string.IsNullOrEmpty(asScreenSave.ContentManagerMethod))
            {
                contentManagerName = asScreenSave.ContentManagerMethod;
            }

            var whatToInheritFrom = GetInheritance(element);
            CodeWriter.SetClassNameAndNamespace(
                projectNamespace,
                objectName,
                stringBuilder,
                !string.IsNullOrEmpty(contentManagerName),
                contentManagerName,
                whatToInheritFrom
                );

            #region Make Activity, Initialize, PostInitalize, and Destroy "override" if necessary

            if ( element.InheritsFromElement())
            {

                if (stringBuilder.Contains("virtual void Initialize"))
                {
                    stringBuilder.Replace("virtual void Initialize", "override void Initialize");
                }

                if (stringBuilder.Contains("virtual void Activity"))
                {
                    stringBuilder.Replace("virtual void Activity", "override void Activity");
                }

                if (stringBuilder.Contains("virtual void Destroy"))
                {
                    stringBuilder.Replace("virtual void Destroy", "override void Destroy");
                }
            }

            #endregion

            try
            {
                CodeWriter.GenerateUsings(stringBuilder, element);
            }
            catch (Exception e)
            {
                string stackTrace = e.StackTrace;

                throw new Exception("Error trying to generate using statements for " + element + "\n\n" + stackTrace, e);
            }

            #region Generate Fields

            ICodeBlock fieldsSection = CodeWriter.GenerateFields(element);
            int startOfFieldsSection = CodeWriter.GetIndexAfter("// Generated Fields", stringBuilder);
开发者ID:GorillaOne,项目名称:FlatRedBall,代码行数:67,代码来源:CodeWriter.cs

示例13: GetAttributeValue

        public IEnumerable<string> GetAttributeValue(string data, string template, string attributeName)
        {            
            template = ClearContent(template);

            var templateParts = template.ToLower().Split('*');
            var content = new StringBuilder(data.ToLower());
            ClearContent(content);
            template = ClearContent(template);
            int startPos = content.Contains(templateParts[0]);
            if (startPos == -1) yield return string.Empty;
            
            int endPos = content.Contains(templateParts[1], startPos + templateParts[0].Length - 1);

            if (startPos != -1 && endPos != -1)
            {
                content.Remove(0, startPos);
                startPos = content.Contains(templateParts[0]);
                endPos = content.Contains(templateParts[1], startPos + templateParts[0].Length - 1);
                if (startPos != -1 && endPos != -1)
                {
                    content.Remove(endPos + templateParts[1].Length, content.Length - (endPos + templateParts[1].Length));
                }
            }            

            while (startPos != -1 && endPos != -1)
            {
                startPos = content.Contains(attributeName, startPos);
                if (startPos == -1) yield return string.Empty;//return result;

                endPos = content.Contains(">", startPos);
                if (endPos == -1) yield return string.Empty;  //return result;

                char[] destination = new char[endPos - (startPos + attributeName.Length)];
                content.CopyTo(startPos + attributeName.Length, destination, 0, endPos - (startPos + attributeName.Length));
                int breakPos = -1;
                for (int i = 0; i < destination.Length; i++)
                    if (destination[i] == ' ')
                    {
                        breakPos = i;
                        break;
                    }
                if (breakPos > -1)
                {
                    Array.Resize<char>(ref destination, breakPos);
                }


                string link = new string(destination);
                //if (!link.StartsWith("host"))
                //    link = host + '/' + link;
                //link = link.Replace("/./", "/");

                //result.Add(link);
                startPos = content.Contains(attributeName, endPos);
                endPos = content.Contains(">", startPos + attributeName.Length - 1);
                yield return RemoveTags(link);
            }
            yield return string.Empty;//return result;
        }
开发者ID:MaxIakovliev,项目名称:asp.net-mvc-real-estate,代码行数:59,代码来源:HtmlParser.cs

示例14: GetSingleContent

        public string GetSingleContent(string data, string template)
        {
            var templateParts = template.ToLower().Split('*');
            if (templateParts != null && templateParts.Length == 2)
            {
                templateParts[0] = ClearContent(templateParts[0]);
                templateParts[1] = ClearContent(templateParts[1]);
            }
            var content = new StringBuilder(data.ToLower());
            ClearContent(content);
            int startPos = content.Contains(templateParts[0]);
            if (startPos == -1) return string.Empty;
            int endPos = content.Contains(templateParts[1], startPos + templateParts[0].Length );
            if (startPos != -1 && endPos != -1)
            {
                char[] destination = new char[endPos - startPos + templateParts[0].Length];
                content.CopyTo(startPos + templateParts[0].Length, destination, 0, endPos - (startPos + templateParts[0].Length));
                string result = new string(destination);

                content = null;

                return result;//RemoveTags(result).Trim();
            }
            content = null;
            return string.Empty;//return result;
        }
开发者ID:MaxIakovliev,项目名称:asp.net-mvc-real-estate,代码行数:26,代码来源:HtmlParser.cs

示例15: 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


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