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


C# StringBuilder.Clear方法代码示例

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


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

示例1: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            try {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    List<byte> bytes = new List<byte>();
                    BinaryReader br = new BinaryReader(File.Open(openFileDialog1.FileName, FileMode.Open));
                    while (!(br.BaseStream.Position >= br.BaseStream.Length))
                    {
                        bytes.Add(br.ReadByte());
                    }
                    br.Close();

                    //BitArray plain = new BitArray(bytes.ToArray());
                    StringBuilder sb = new StringBuilder();

                    foreach (byte b in bytes)
                    {
                        sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
                    }
                    richTextBox1.Text = sb.ToString();
                    sb.Clear();

                    LFSR lfsr = new LFSR(new List<int>() { 28, 3 },
                        Services.StringToBooleanArray(textBox1.Text).ToList(), bytes.ToArray());

                    byte[] cipher = lfsr.GetNewBitArray();

                    foreach (byte b in cipher)
                    {
                        string curByte = Convert.ToString(b, 2).PadLeft(8, '0');
                        for (int i = 0; i < 8; i++)
                        {
                            sb.Append(curByte[i]);
                        }
                        sb.Append(" ");
                    }

                    richTextBox3.Text = sb.ToString();
                    sb.Clear();

                    richTextBox2.Text = Services.BoolArrayToString(lfsr.Key);

                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        BinaryWriter bw = new BinaryWriter(File.Create(saveFileDialog1.FileName));
                        bw.Write(Services.BitArrayToByteArray(new BitArray(cipher)));
                        bw.Close();
                    }
                }
            }
            catch
            {

            }
            finally
            {

            }
        }
开发者ID:zhenyabohon,项目名称:LFSR-RC4,代码行数:60,代码来源:Form1.cs

示例2: ReadWords

        static void ReadWords()
        {
            int N = int.Parse(Console.ReadLine());

            for (int i = 0; i < N; i++)
            {
                string inputLine = Console.ReadLine().ToLower();
                var word = new StringBuilder();

                for (int j = 0; j < inputLine.Length; j++)
                {
                    if (inputLine[j] >= 'a' && inputLine[j] <= 'z')
                    {
                        word.Append(inputLine[j]);
                    }
                    else if (inputLine[j] >= 'A' && inputLine[j] <= 'Z')
                    {
                        word.Append((char)inputLine[j] - 'A' + 'a');
                    }
                    else if (word.Length > 0)
                    {
                        AddWord(word.ToString());
                        word.Clear();
                    }
                }

                if (word.Length > 0)
                {
                    AddWord(word.ToString());
                    word.Clear();
                }
            }
        }
开发者ID:Nottyy,项目名称:TelerikAcademy,代码行数:33,代码来源:Words.cs

示例3: InsertModel

 public int InsertModel(SphinxExcludeQuery model)
 {
     StringBuilder sqlStr = new StringBuilder();
     try
     {
         sqlStr.AppendFormat("select count(product_id) from sphinx_exclude where product_id={0}", model.product_id);
         if(accessMySql.getDataTable(sqlStr.ToString()).Rows[0][0].ToString()!="0")
         {
             return -1;
         }
         sqlStr.Clear();
         sqlStr.AppendFormat("select count(product_id) from product where product_id={0}",model.product_id);
         if (accessMySql.getDataTable(sqlStr.ToString()).Rows[0][0].ToString() == "0")
         {
             return -2;
         }
         sqlStr.Clear();
         sqlStr.AppendFormat("insert sphinx_exclude(product_id,kdate,kuser) values({0},'{1}','{2}')", model.product_id, Common.CommonFunction.DateTimeToString(DateTime.Now),(System.Web.HttpContext.Current.Session["caller"] as Caller).user_id);
         return accessMySql.execCommand(sqlStr.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("SphinxExcludeDao-->InsertModel-->" + ex.Message + sqlStr.ToString(), ex);
     }
 }
开发者ID:lxh2014,项目名称:gigade-net,代码行数:25,代码来源:SphinxExcludeDao.cs

示例4: Main

    static void Main()
    {
        string text = "Sos, bob ili potop, ABBA slusham az!";

        string[] words = text.Split(' ', ',', '.');
        string element = "";

        StringBuilder firstPart = new StringBuilder();
        StringBuilder secondPart = new StringBuilder();

        for (int i = 0; i < words.Length; i++)
        {
            element = words[i];
            string firstHalf = "";
            string secondHalf = "";
            if (element.Length % 2 == 0 && element!= "")
            {
                for (int j = 0; j < element.Length / 2; j++)
                {
                    firstPart.Append(element[j]);
                }

                for (int j = element.Length - 1; j >= element.Length / 2; j--)
                {
                    secondPart.Append(element[j]);
                }
                firstHalf = firstPart.ToString();
                secondHalf = secondPart.ToString();
                firstPart.Clear();
                secondPart.Clear();
                int compare = string.Compare(firstHalf, secondHalf, StringComparison.InvariantCultureIgnoreCase);
                if (compare == 0)
                {
                    Console.WriteLine(element);
                }
            }

            else if(element.Length % 2 != 0 && element!= "")
            {
                for (int j = 0; j < element.Length / 2; j++)
                {
                    firstPart.Append(element[j]);
                }

                for (int j = element.Length - 1; j >= element.Length / 2 + 1; j--)
                {
                    secondPart.Append(element[j]);
                }
                firstHalf = firstPart.ToString();
                secondHalf = secondPart.ToString();
                firstPart.Clear();
                secondPart.Clear();
                int compare = string.Compare(firstHalf, secondHalf, StringComparison.InvariantCultureIgnoreCase);
                if (compare == 0)
                {
                    Console.WriteLine(element);
                }
            }
        }
    }
开发者ID:NikolovNikolay,项目名称:Telerik-Homeworks,代码行数:60,代码来源:Palindromes.cs

示例5: MaximumDraws

 public void MaximumDraws()
 {
     // This function has a objetive to solve this challenge: https://www.hackerrank.com/challenges/maximum-draws
     // The first line contains the number of test cases.
     // The next T lines contains an integer N which indicates the total pairs of socks present in the drawer.
     StringBuilder vs_Input = new StringBuilder();
     string vs_received = string.Empty;
     string vs_expected = string.Empty;
     vs_expected = "2\n3";
     vs_Input.Append("2\n");
     vs_Input.Append("1\n");
     vs_Input.Append("2\n");
     vs_received = HackerHank.Challengers.MaximumDraws(vs_Input.ToString());
     Assert.AreEqual(vs_expected, vs_received);
     vs_Input.Clear();
     // Second test 
     vs_expected = "5";
     vs_Input.Append("1\n");
     vs_Input.Append("4\n");
     vs_received = HackerHank.Challengers.MaximumDraws(vs_Input.ToString());
     Assert.AreEqual(vs_expected, vs_received);
     // Third test 
     vs_Input.Clear();
     vs_expected = "4";
     vs_Input.Append("1\n");
     vs_Input.Append("3\n");
     vs_received = HackerHank.Challengers.MaximumDraws(vs_Input.ToString());
     Assert.AreEqual(vs_expected, vs_received);
 }
开发者ID:cezarant,项目名称:DesafiosHackerHank,代码行数:29,代码来源:TestMathChallenger.cs

示例6: Main

    static void Main()
    {
        StringBuilder sb = new StringBuilder();
        int n = int.Parse(Console.ReadLine());
        int step = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            sb.Append(Convert.ToString(int.Parse(Console.ReadLine()), 2).PadLeft(8, '0'));
        }

        char[] numsBytes = sb.ToString().ToCharArray();
        sb.Clear();

        numsBytes[0] = (numsBytes[0] == '0') ? '1' : '0';
        for (int i = step; i < numsBytes.Length; i += step)
        {
            numsBytes[i] = (numsBytes[i] == '0') ? '1' : '0';
        }

        int counter = 0;
        for (int i = 0; i < numsBytes.Length; i++)
        {
            sb.Append(numsBytes[i]);
            ++counter;
            if (counter == 8)
            {
                Console.WriteLine(Convert.ToInt16(sb.ToString(), 2));
                sb.Clear();
                counter = 0;
            }
        }
        Console.Read();
    }
开发者ID:kaloyan-penkov,项目名称:SoftUni,代码行数:33,代码来源:BitsInverter.cs

示例7: GetEnumerator

 // Enumeratori
 public IEnumerator GetEnumerator()
 {
     StringBuilder sout = new StringBuilder();
     sout.Clear();
     foreach(char c in t)
         {
         if(s.Contains(c.ToString()))
             {
             if( ((sout.ToString()).Trim()).Length > 0)
                 {
                 yield return sout.ToString().Trim();
                 sout.Clear();
                 }
             }
         else
             {
             sout.Append(c);
             }
         }
     if (((sout.ToString()).Trim()).Length > 0)
         {
         yield return sout.ToString().Trim();
         sout.Clear();
         }
     yield break;
 }
开发者ID:Fred68,项目名称:Utilita,代码行数:27,代码来源:TokenString.cs

示例8: GetWords

        private static string[] GetWords(string text)
        {
            List<string> words = new List<string>();
            StringBuilder word = new StringBuilder();

            for (int i = 0; i < text.Length; i++)
            {
                char c = text[i];

                if (char.IsLetter(c))
                {
                    word.Append(c);
                }
                else
                {
                    if (word.Length > 1)
                    {
                        words.Add(word.ToString());
                    }

                    word.Clear();
                }
            }

            if (word.Length > 1)
            {
                words.Add(word.ToString());
                word.Clear();
            }

            return words.ToArray();
        }
开发者ID:razsilev,项目名称:TelerikAcademy_Homework,代码行数:32,代码来源:CountWords.cs

示例9: SaveItem

        /// <summary>
        /// Method to save item
        /// </summary>
        /// <param name="itemMl"></param>
        /// <returns></returns>
        public int SaveItem(ItemModel itemMl)
        {
            // Creating instance of the string builder class to hold the tracing data
            StringBuilder objStringBuilderTrace = new StringBuilder();
            item objItem = new item();

            // Append tracing into string builder
            objStringBuilderTrace.AppendLine("Start method : SaveItem(ItemModel itemML) :: JetstreamLaunchpad.DAL.Item class : DBItem.cs");
            // Writing trace log into the log file 
            SaveLogger.SaveLoggerTrace(objStringBuilderTrace.ToString());
            // Clear StringBuilder object
            objStringBuilderTrace.Clear();

            objItem.Material = itemMl.Material;
            objItem.Batch = itemMl.Batch;
            objItem.ExpirationDate = itemMl.ExpirationDate;
            objItem.EPC = itemMl.EPC;

            ObjTersoDataContext.items.Add(objItem);
            ObjTersoDataContext.SaveChanges();
            var itemId = itemMl.ItemId;

            // Append tracing into string builder
            objStringBuilderTrace.AppendLine("End method : SaveItem(ItemModel itemML) :: JetstreamLaunchpad.DAL.Item class : DBItem.cs");
            // Writing trace log into the log file 
            SaveLogger.SaveLoggerTrace(objStringBuilderTrace.ToString());
            objStringBuilderTrace.Clear();
            return itemId;
        }
开发者ID:tersosolutions,项目名称:JetstreamSDK-.NET_Launchpad,代码行数:34,代码来源:DBItem.cs

示例10: ComplexParseResult

 internal ComplexParseResult(List<ParseResult> parts)
 {
     List<ParseResult> my = new List<ParseResult>();
     StringBuilder sb = new StringBuilder();
     int totalLength = 0;
     foreach (ParseResult part in flatten(parts)) {
         if (part.type == ParseResultType.UNPARSED) {
             sb.Append(((UnparsedParseResult)part).text);
         } else {
             if (sb.Length > 0) {
                 my.Add(ParseResult.unparsed(sb.ToString()));
                 totalLength += sb.Length;
                 sb.Clear();
             }
             my.Add(part);
             totalLength += part.length;
         }
     }
     if (sb.Length > 0) {
         my.Add(ParseResult.unparsed(sb.ToString()));
         totalLength += sb.Length;
         sb.Clear();
     }
     this.totalLength = totalLength;
     this.parts = new ReadOnlyCollection<ParseResult>(my);
 }
开发者ID:wareya,项目名称:chiitrans,代码行数:26,代码来源:ComplexParseResult.cs

示例11: LoadData

		public void LoadData()
		{
			StringBuilder sBuilder = new StringBuilder(_maxBufferSize);	// Assum 1024 is a big enough number to contain all chars

			NativeMethods.GetLicensedFeatureListDelimitedBy_Win32(_delimiter, sBuilder, _maxBufferSize);
			string strFeatures = sBuilder.ToString();
			sBuilder.Clear();
			if (string.IsNullOrEmpty(strFeatures))
			{
				return;
			}
			string[] features = strFeatures.Split(_delimiter.ToCharArray());

			foreach (string feature in features)
			{
				NativeMethods.GetFeatureDetailsDelimitedBy_Win32(feature, _delimiter, sBuilder, _maxBufferSize);
				string strDetails = sBuilder.ToString();
				sBuilder.Clear();
				if (string.IsNullOrEmpty(strDetails))
				{
					continue;
				}

				string[] details = strDetails.Split(_delimiter.ToCharArray());
				if (details.Length < 6)
				{
					continue;
				}
				Licences.Add(new Licence(details[0], GetFeatureDisplayName(details[0]), details[0], details[1], details[2], details[3], details[4], details[5]));
			}
		}
开发者ID:killbug2004,项目名称:WSProf,代码行数:31,代码来源:LicenceCollection.cs

示例12: Extraxt

        static string[] Extraxt(string address)
        {
            string[] info = new string[3];
            StringBuilder sb = new StringBuilder();

            int firstSepIndex = address.IndexOf("://"); //index of the first seperator
            int secondSepIndex = address.IndexOf('/', firstSepIndex + 3); //index of the second separator

            for (int i = 0; i < firstSepIndex; i++) //protocol
            {
                sb.Append(address[i]);
            }
            info[0] = sb.ToString();
            sb.Clear();

            for (int i = firstSepIndex + 3; i < secondSepIndex; i++) //server
            {
                sb.Append(address[i]);
            }
            info[1] = sb.ToString();
            sb.Clear();

            for (int i = secondSepIndex; i < address.Length; i++) //resource
            {
                sb.Append(address[i]);
            }
            info[2] = sb.ToString();

            return info;
        }
开发者ID:dlvasilev,项目名称:Telerik-School-Academy,代码行数:30,代码来源:ExtractFromAddress.cs

示例13: Read

 public ISet<Word> Read(string source)
 {
     ISet<Word> result = new HashSet<Word>();
     string readstring = GetString(source);
     bool skiptonextspace = false;
     StringBuilder stringbuilder = new StringBuilder(20);
     foreach (char c in readstring) {
         if (!skiptonextspace) {
             if (char.IsLetter(c)) {
                 stringbuilder.Append(c);
             } else if (IsSpecialCharacter(c)) {
                 string newstring = stringbuilder.ToString();
                 if (newstring.Length > 0) { // Only add if the new word isn't the empty string.
                     newstring = newstring.ToLowerInvariant();
                     result.Add(new Word(newstring));
                     stringbuilder.Clear();
                 }
             } else { // The word contains a number or a symbol not listed in 'specialchars' and the program skips to the next word.
                 stringbuilder.Clear();
                 skiptonextspace = true;
             }
         } else if (c == ' ') {
             skiptonextspace = false;
         }
     }
     return result;
 }
开发者ID:kiniry-supervision,项目名称:VocabularyBuilder,代码行数:27,代码来源:Reader.cs

示例14: SimpleTest

        private static void SimpleTest(Enums.MediaType type)
        {
            #region 建立一个item
            StringBuilder st = new StringBuilder();
            string[] article = File.ReadAllLines(@"1.txt");
            ItemToDuplication s = new ItemToDuplication(new Item());
            s.ItemID = "source"; s.MediaType = type; s.SpliteTitle = article[0]; s.PubDate = DateTime.Now;
            st.Clear();
            for (int i = 1; i < article.Length; ++i)
                st.Append(article[i]);
            s.SpliteText = st.ToString();
            #endregion

            //将刚才建立的item添加到myDetector中
            myDetector.TestAndTryAdd(s);

            #region 建立一个测试item
            article = File.ReadAllLines(@"2.txt");
            //s = new ItemToDuplication();
            s.ItemID = "test"; s.MediaType = type; s.SpliteTitle = article[0]; s.PubDate = DateTime.Now;
            st.Clear();
            for (int i = 1; i < article.Length; ++i)
                st.Append(article[i]);
            s.SpliteText = st.ToString();
            #endregion

            //测试转载检测
            string id = null;
            id = myDetector.TestAndTryAdd(s);
            if (id != null)
                Console.WriteLine("Copied Item: " + id);
            else Console.WriteLine("Not copied.");
        }
开发者ID:Hanjun-Dai,项目名称:DuplicationDetector,代码行数:33,代码来源:Client.cs

示例15: Main

 static void Main(string[] args)
 {
     System.Array.Sort(args);
     for (int i = 0; i < args.Length; i++)
     {
         Console.WriteLine((i+1) + ". " + args[i]);
     }
     Console.WriteLine();
     StringBuilder sb = new StringBuilder();
     sb.Clear();
     for (int i = 0; i < args.Length; i++)
     {
         sb.Append(args[i]);
     }
     Console.WriteLine(sb.ToString());
     Console.WriteLine();
     for (int i = 0; i < args.Length; i++)
     {
         sb.Clear();
         sb.Append(args[i].Length);
         sb.Append(" ");
         sb.Append(args[i]);
         Console.WriteLine(sb);
     }
     Console.ReadLine();
 }
开发者ID:st-mrazik,项目名称:POT,代码行数:26,代码来源:Program.cs


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