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


C# StringBuilder.Clear方法代码示例

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


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

示例1: Split

 /// <summary>
 /// Разбить на слова.
 /// </summary>
 /// <param name="src">Исходная строка.</param>
 /// <returns>Разбитая на слова строка.</returns>
 public IEnumerable<string> Split(string src)
 {
     var sb = new StringBuilder();
     for (int i = 0; i < src.Length; i++)
     {
         var ch = src[i];
         if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
         {
             sb.Append(' ');
             yield return sb.ToString();
             sb.Clear();
         }
         else
         {
             sb.Append(ch);
             //if (ch == '.' || ch == ',' || ch == ':' || ch == '/' || ch == '\\' || ch == '#' || ch =='?' || ch == '!' || ch == '*' || ch == '-')
             if (char.IsPunctuation(ch) || ch == '.' || ch == ',' || ch == ':' || ch == '/' || ch == '\\' || ch == '#' || ch == '?' || ch == '!' || ch == '*' || ch == '-')
             {
                 yield return sb.ToString();
                 sb.Clear();
             }
         }
     }
     if (sb.Length > 0)
     {
         yield return sb.ToString();
     }
 }
开发者ID:Opiumtm,项目名称:DvachBrowser3,代码行数:33,代码来源:WordSplitter.cs

示例2: GetTokens

        private IEnumerable<string> GetTokens() {
            var token = new StringBuilder();
            var lastCharacter = '\0';
            foreach (var character in _xPath) {
                if (IsQuote(lastCharacter)) {
                    token.Append(character);
                    if (character == lastCharacter) {
                        yield return token.ToString();
                        token.Clear();
                        lastCharacter = '\0';
                    }
                    continue;
                }

                if (IsQuote(character) || IsName(character) != IsName(lastCharacter)) {
                    if (token.Length > 0)
                        yield return TrimToken(token);
                    token.Clear();
                }
                token.Append(character);
                lastCharacter = character;
            }
            if (token.Length > 0)
                yield return TrimToken(token);
        }
开发者ID:OnpointOnDemand,项目名称:fluentjdf,代码行数:25,代码来源:XPathDecorator.cs

示例3: Main

        static void Main(string[] args)
        {
            var text1 = File.ReadAllBytes(@"..\doc\pi.t");
              var text2 = File.ReadAllBytes(@"..\doc\e.t");

              var comparer = new Comparer();
              var k = 5;

              var result = comparer.Compare(text1, text2, k);

              var sb = new StringBuilder();
              sb.AppendLine(string.Format("Max length: {0}\n", result.MaxLength));
              using (var file = System.IO.File.AppendText(@"..\doc\pie.t"))
              {
            file.Write(sb.ToString());
            sb.Clear();
            foreach (var index in result.Indices)
            {
              sb.AppendLine(string.Format("Length: {0}, pi_index: {1}, e_index: {2}",
            index.Value,
            index.Key.Item1,
            index.Key.Item2));
              file.Write(sb.ToString());
              sb.Clear();
            }
              }
        }
开发者ID:jarocky,项目名称:PatternSearch,代码行数:27,代码来源:Program.cs

示例4: AppendIntTest

        public void AppendIntTest()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
              StringBuilder stringBuilder = new StringBuilder();

              stringBuilder.AppendNumber(1234567890);
              Assert.AreEqual("1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(-1234567890);
              Assert.AreEqual("-1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.None);
              Assert.AreEqual("1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.PositiveSign);
              Assert.AreEqual("+1234567890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.NumberGroup);
              Assert.AreEqual("1,234,567,890", stringBuilder.ToString());

              stringBuilder.Clear();
              stringBuilder.AppendNumber(1234567890, AppendNumberOptions.PositiveSign | AppendNumberOptions.NumberGroup);
              Assert.AreEqual("+1,234,567,890", stringBuilder.ToString());
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:28,代码来源:StringBuilderHelperTest.cs

示例5: SplitAndLower

        private static IEnumerable<string> SplitAndLower(string source)
        {
            var strings = new List<string>();
            var builder = new StringBuilder();

            foreach (var character in source)
            {
                if (IsSeparator(character))
                {
                    if (builder.Length > 0)
                    {
                        strings.Add(builder.ToString());
                    }

                    builder.Clear();
                    continue;
                }
                else if (char.IsUpper(character) && builder.Length > 0)
                {
                    strings.Add(builder.ToString());
                    builder.Clear();
                }

                builder.Append(char.ToLowerInvariant(character));
            }

            if (builder.Length > 0)
            {
                strings.Add(builder.ToString());
            }

            return strings;
        }
开发者ID:markwalsh-liverpool,项目名称:saule,代码行数:33,代码来源:StringExtensions.cs

示例6: ReverseWords

    public string ReverseWords(string s) {
        var sb = new StringBuilder();
        var wordList = new List<string>();
        foreach (var ch in s)
        {
            if (char.IsWhiteSpace(ch))
            {
                if (sb.Length > 0)
                {
                    wordList.Add(sb.ToString());
                    sb.Clear();
                }
            }
            else
            {
                sb.Append(ch);
            }
        }
        if (sb.Length > 0)
        {
            wordList.Add(sb.ToString());
            sb.Clear();
        }
        
        foreach (var word in ((IEnumerable<string>)wordList).Reverse())
        {
            if (sb.Length > 0)
            {
                sb.Append(' ');
            }
            sb.Append(word);
        }

        return sb.ToString();
    }
开发者ID:alexguo88,项目名称:LeetCode,代码行数:35,代码来源:151.ReverseWordsInAString.cs

示例7: TestEagerlyLoadingMultipleLevels

        public void TestEagerlyLoadingMultipleLevels()
        {
            using (var context = new TestDB2015Entities())
            {
                var databaseLog = new StringBuilder();
                context.Database.Log = commandLine =>
                {
                    databaseLog.AppendLine(commandLine);
                    Trace.Write(commandLine);
                };

                Trace.WriteLine("a normal query");
                var product1IncludeTags = context.Users
                                                 .Include(x => x.Products)
                                                 .Include(x => x.Products.Select(y => y.Tags))
                                                 .FirstOrDefault();
                Assert.IsNotNull(product1IncludeTags);

                Trace.WriteLine("1st query using Include method.");
                databaseLog.Clear();
                var debugInfo1 = new EFCacheDebugInfo();
                var firstPoductIncludeTags = context.Users
                                                    .Include(x => x.Products)
                                                    .Include(x => x.Products.Select(y => y.Tags))
                                                    .Cacheable(debugInfo1)
                                                    .FirstOrDefault();
                Assert.IsNotNull(firstPoductIncludeTags);
                Assert.AreEqual(false, debugInfo1.IsCacheHit);
                var hash1 = debugInfo1.EFCacheKey.KeyHash;
                var cacheDependencies1 = debugInfo1.EFCacheKey.CacheDependencies;

                Trace.WriteLine("same cached query using Include method.");
                databaseLog.Clear();
                var debugInfo11 = new EFCacheDebugInfo();
                var firstPoductIncludeTags11 = context.Users
                                                    .Include(x => x.Products)
                                                    .Include(x => x.Products.Select(y => y.Tags))
                                                    .Cacheable(debugInfo11)
                                                    .FirstOrDefault();
                Assert.IsNotNull(firstPoductIncludeTags11);
                Assert.AreEqual(true, debugInfo11.IsCacheHit);

                Trace.WriteLine(
                    @"2nd query looks the same, but it doesn't have the Include method, so it shouldn't produce the same queryKeyHash.
                 This was the problem with just parsing the LINQ expression, without considering the produced SQL.");
                databaseLog.Clear();
                var debugInfo2 = new EFCacheDebugInfo();
                var firstPoduct = context.Users.Cacheable(debugInfo2)
                                               .FirstOrDefault();
                Assert.IsNotNull(firstPoduct);
                Assert.AreEqual(false, debugInfo2.IsCacheHit);
                var hash2 = debugInfo2.EFCacheKey.KeyHash;
                var cacheDependencies2 = debugInfo2.EFCacheKey.CacheDependencies;

                Assert.AreNotEqual(hash1, hash2);
                Assert.AreNotEqual(cacheDependencies1, cacheDependencies2);
            }
        }
开发者ID:yao-yi,项目名称:EFSecondLevelCache,代码行数:58,代码来源:UnitTests.cs

示例8: Split

        internal static IEnumerable<string> Split(string expression)
        {
            List<string> result = new List<string>();

            StringBuilder resultItemBuilder = new StringBuilder();
            List<char> charArray = expression.ToList();
            for (int i = 0; i < charArray.Count; i++)
            {
                string oneCharString = charArray[i].ToString(CultureInfo.InvariantCulture);
                string twoCharString = oneCharString;
                // 读取两个字符,判断是不是特殊双字符的操作符.etc: >=, <=, &&, ||
                if (i < charArray.Count - 1)
                {
                    twoCharString += charArray[i + 1].ToString(CultureInfo.InvariantCulture);
                }

                if (OperatorMethod.IsOperator(twoCharString) &&
                    twoCharString.Length == 2)
                {
                    if (resultItemBuilder.Length > 0)
                    {
                        result.Add(resultItemBuilder.ToString());
                        resultItemBuilder.Clear();
                    }

                    result.Add(twoCharString);
                    i++;
                }
                else if (OperatorMethod.IsOperator(oneCharString))
                {
                    if (resultItemBuilder.Length > 0)
                    {
                        result.Add(resultItemBuilder.ToString());
                        resultItemBuilder.Clear();
                    }

                    result.Add(oneCharString);
                }
                else
                {
                    resultItemBuilder.Append(oneCharString);
                }
            }

            if (resultItemBuilder.Length > 0)
            {
                result.Add(resultItemBuilder.ToString());
                resultItemBuilder.Clear();
            }

            return result;
        }
开发者ID:philfanzhou,项目名称:PredictFuture,代码行数:52,代码来源:ExpressionSpliter.cs

示例9: GetContractOutStockSelect

        public SelectModel GetContractOutStockSelect(int pageIndex, int pageSize, string orderStr, string stockName, DateTime beginDate, DateTime endDate, string stockIds = "")
        {
            NFMT.Common.SelectModel select = new NFMT.Common.SelectModel();

            select.PageIndex = pageIndex;
            select.PageSize = pageSize;
            if (string.IsNullOrEmpty(orderStr))
                select.OrderStr = "sto.StockId desc";
            else
                select.OrderStr = orderStr;

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("sto.StockId,sn.RefNo,sto.AssetId,ass.AssetName,sto.BrandId,bra.BrandName,sto.Format,sto.OriginPlace,sto.CurNetAmount,sto.DeliverPlaceId");
            sb.Append(",dp.DPName,sto.StockDate,sto.UintId,mu.MUName,sto.CustomsType,ct.DetailName as CustomsTypeName,sto.CardNo,sto.StockStatus,ss.StatusName");
            sb.Append(",se.ExclusiveAmount, ISNULL(sto.CurNetAmount,0) - ISNULL(se.ExclusiveAmount,0) as NetAmount, ISNULL(sto.CurNetAmount,0) - ISNULL(se.ExclusiveAmount,0) as OutAmount,sto.Bundles,sto.Bundles as OutBundles");
            select.ColumnName = sb.ToString();

            int readyStatus = (int)Common.StatusEnum.已生效;

            sb.Clear();
            sb.Append(" dbo.St_Stock sto ");
            sb.Append("  inner join dbo.St_StockName sn on sto.StockNameId = sn.StockNameId ");

            sb.Append(" left join NFMT_Basic.dbo.Asset ass on sto.AssetId = ass.AssetId ");
            sb.Append(" left join NFMT_Basic.dbo.Brand bra on sto.BrandId = bra.BrandId ");
            sb.Append(" left join NFMT_Basic.dbo.DeliverPlace dp on sto.DeliverPlaceId = dp.DPId ");
            sb.Append(" left join NFMT_Basic.dbo.MeasureUnit mu on sto.UintId= mu.MUId ");
            sb.Append(" left join NFMT_Basic.dbo.BDStyleDetail ct on ct.StyleDetailId = sto.CustomsType ");
            sb.Append("  left join NFMT_Basic.dbo.BDStatusDetail ss on ss.DetailId = sto.StockStatus ");

            sb.AppendFormat("  left join (select Sum(ExclusiveAmount) as ExclusiveAmount,StockId from dbo.St_StockExclusive where ExclusiveStatus = {0} group by StockId ) as se on se.StockId = sto.StockId ", readyStatus);
            select.TableName = sb.ToString();

            sb.Clear();
            sb.AppendFormat(" sto.StockStatus in ({0},{1},{2}) ", (int)StockStatusEnum.预入库存, (int)StockStatusEnum.在库正常, (int)StockStatusEnum.新拆库存);
            sb.Append(" and ISNULL(sto.CurNetAmount,0) - ISNULL(se.ExclusiveAmount,0) >0 ");

            if (!string.IsNullOrEmpty(stockName))
                sb.AppendFormat(" and sn.RefNo like '%{0}%' ", stockName);
            if (beginDate > Common.DefaultValue.DefaultTime && endDate > beginDate)
                sb.AppendFormat(" and sto.StockDate between '{0}' and '{1}' ", beginDate.ToString(), endDate.AddDays(1).ToString());

            if (!string.IsNullOrEmpty(stockIds))
                sb.AppendFormat(" and sto.StockId in ({0})", stockIds);

            select.WhereStr = sb.ToString();

            return select;
        }
开发者ID:weiliji,项目名称:NFMT,代码行数:49,代码来源:StockLogBLL.cs

示例10: Tokenize

        /// <summary>
        /// Iterator that builds tokens from the inputted document, and returns them as they are built.
        /// </summary>
        /// <param name="document">The document to tokenize</param>
        /// <returns>Returns lowercase tokens, one at a time as soon as they are read</returns>
        public IEnumerable<string> Tokenize(string document)
        {
            StringBuilder token = new StringBuilder();
            foreach(char character in document)
            {
                if (ignoreList.Contains(character))
                {
                    if (token.Length > 0)
                    {
                        string result = token.ToString().ToLower();
                        token.Clear();
                        if (this.isValidTerm(result))    // dont return stop words
                        {
                            yield return result;
                        }

                    }
                }
                else
                {
                    token.Append(character);
                }
            }

            if (token.Length > 0)
            {
                yield return token.ToString().ToLower();
            }
        }
开发者ID:tristanstcyr,项目名称:SPIMI,代码行数:34,代码来源:BasicLexer.cs

示例11: CipherDecoder

        public CipherDecoder(string secretCode, string cipher)
        {
            cipherItems = new List<CipherItem>();

            StringBuilder currentCipher = new StringBuilder();
            char lastChar = '\0';
            foreach (char ch in cipher)
            {
                if (ch >= 'A' && ch <= 'Z')
                {
                    if (currentCipher.Length > 0)
                    {
                        cipherItems.Add(new CipherItem(lastChar, currentCipher.ToString()));
                        currentCipher.Clear();
                    }
                    lastChar = ch;
                }
                else
                {
                    currentCipher.Append(ch);
                }
            }
            if (currentCipher.Length > 0)
            {
                cipherItems.Add(new CipherItem(lastChar, currentCipher.ToString()));
            }

            this.secretCode = secretCode;
        }
开发者ID:nedevny,项目名称:TelerikAkademy,代码行数:29,代码来源:CipherDecoder.cs

示例12: CountAndSay

        public string CountAndSay(int n)
        {
            var result = "1";
            char currentCh;
            int i, j, startNum;
            var builder = new StringBuilder();

            for (i = 1; i < n; i++)
            {
                currentCh = result[0];
                startNum = 0;
                for (j = 1; j < result.Length; j++)
                {
                    if (currentCh != result[j])
                    {
                        builder.Append(j - startNum);
                        builder.Append(currentCh);
                        currentCh = result[j];
                        startNum = j;
                    }
                }
                builder.Append(j - startNum);
                builder.Append(currentCh);

                result = builder.ToString();
                builder.Clear();
            }

            return result;
        }
开发者ID:BigEgg,项目名称:LeetCode,代码行数:30,代码来源:038-CountAndSay.cs

示例13: GetEditProblemViewModel

        public static EditProblemViewModel GetEditProblemViewModel(Problem problem)
        {
            var epvm = new EditProblemViewModel();
            epvm.Author = problem.Author.UserName;
            epvm.Name = problem.Name;
            epvm.Text = problem.Text;
            epvm.SelectedCategoryId = problem.CategoryId;
            epvm.IsBlocked = problem.IsBlocked;

            var sb = new StringBuilder();
            foreach (var tag in problem.Tags)
            {
                sb.Append(tag.Name);
                sb.Append(',');
            }

            epvm.TagsString = sb.ToString();

            sb.Clear();

            foreach (var ans in problem.CorrectAnswers)
            {
                sb.Append(ans.Text);
                sb.Append(';');
            }

            sb.Remove(sb.Length - 1, 1);
            epvm.Answers = sb.ToString();

            return epvm;
        }
开发者ID:KA95,项目名称:MyWebApp,代码行数:31,代码来源:GlobalHelper.cs

示例14: Zap

        /// <summary>
        /// Execute any update statements required to clear data, followed by delete statements for all tables.
        /// </summary>
        /// <param name="updateCommands">Update commands to execute</param>
        /// <param name="tables">Tables to delete from</param>
        /// <param name="timeout">Maximum time for a statement</param>
        /// <param name="deleteBatch">Batch delete statements into groups, saves times on databases with large numbers of tables.</param>
        public void Zap(IEnumerable<string> updateCommands, IEnumerable<string> tables, int timeout = 30, int deleteBatch = 1)
        {
            foreach (var item in updateCommands)
            {
                dao.ExecuteNonQuery(item, timeout);
            }

            var sb = new StringBuilder();
            var count = 0;
            foreach (var item in tables)
            {
                sb.AppendLine(string.Format("DELETE FROM {0};", item));
                count++;
                if (count % deleteBatch != 0)
                {
                    continue;
                }

                dao.ExecuteNonQuery(sb.ToString(), timeout);
                sb.Clear();
            }

            var lastCmd = sb.ToString();
            if (!string.IsNullOrEmpty(lastCmd))
            {
                dao.ExecuteNonQuery(lastCmd, timeout);
            }
        }
开发者ID:RustyF,项目名称:EnergyTrading-Core,代码行数:35,代码来源:Zapper.cs

示例15: GetOperationElements

        public List<OperationElement> GetOperationElements(string expression)
        {
            if (string.IsNullOrEmpty(expression))
                throw new EmptyStringException();
            var operationElements = new List<OperationElement>();
            var builder = new StringBuilder();

            foreach (char character in expression)
            {
                if (char.IsDigit(character))
                {
                    builder.Append(character);
                }
                else if (IsOperator(character))
                {
                    if (builder.Length != 0)
                    {
                        operationElements.Add(new OperationElement(OperationElementType.Number, builder.ToString()));
                        builder.Clear();
                    }
                    operationElements.Add(new OperationElement(OperationElementType.Operator, character.ToString()));
                }
                else
                {
                    throw new IncorrectOperationStringException(expression);
                }
            }

            if (builder.Length != 0)
                operationElements.Add(new OperationElement(OperationElementType.Number, builder.ToString()));
            return operationElements;
        }
开发者ID:Andegawen,项目名称:Calculator,代码行数:32,代码来源:ExpressionTransformer.cs


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