當前位置: 首頁>>代碼示例>>C#>>正文


C# StringBuilder.AppendAndPopCharFrom方法代碼示例

本文整理匯總了C#中System.Text.StringBuilder.AppendAndPopCharFrom方法的典型用法代碼示例。如果您正苦於以下問題:C# StringBuilder.AppendAndPopCharFrom方法的具體用法?C# StringBuilder.AppendAndPopCharFrom怎麽用?C# StringBuilder.AppendAndPopCharFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Text.StringBuilder的用法示例。


在下文中一共展示了StringBuilder.AppendAndPopCharFrom方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Decompress

        public static string Decompress(string input)
        {
            var outputBuilder = new StringBuilder();
            var inputBuilder = new StringBuilder(input);

            while(inputBuilder.Length > 0)
            {
                switch (inputBuilder.FirstChar())
                {
                    case MultiVerbatimCharMarker:
                        inputBuilder.PopChar();
                        var length = inputBuilder.PopChar();
                        outputBuilder.AppendAndPopCharFrom(inputBuilder, length);
                        break;
                    case SingleVerbatimCharMarker:
                        inputBuilder.PopChar();
                        outputBuilder.AppendAndPopCharFrom(inputBuilder);
                        break;
                    default:
                        outputBuilder.Append(PartDictionary[inputBuilder.PopChar()]);
                        break;
                }
            }

            return outputBuilder.ToString();
        }
開發者ID:poulfoged,項目名稱:SentenceCompression,代碼行數:26,代碼來源:SentenceCompressor.cs

示例2: Compress

        public static string Compress(string input)
        {
            var outputBuilder = new StringBuilder();
            var inputBuilder = new StringBuilder(input);
            var verbatimBuilder = new StringBuilder();

            while (inputBuilder.Length > 0)
            {
                var possibleParts = PartDictionary
                    .Where(p => inputBuilder.ToString().StartsWith(p))
                    .ToList();

                if (verbatimBuilder.Length == char.MaxValue)
                    FlushVerbatim(outputBuilder, verbatimBuilder);

                if (!possibleParts.Any())
                {
                    verbatimBuilder.AppendAndPopCharFrom(inputBuilder);
                    continue;
                }

                FlushVerbatim(outputBuilder, verbatimBuilder);
                var bestFit = possibleParts.OrderByDescending(p => p.Length).First();
                outputBuilder.Append((char)PartDictionary.ToList().IndexOf(bestFit));
                inputBuilder.Remove(0, bestFit.Length);
            }

            FlushVerbatim(outputBuilder, verbatimBuilder);
            return outputBuilder.ToString();
        }
開發者ID:poulfoged,項目名稱:SentenceCompression,代碼行數:30,代碼來源:SentenceCompressor.cs


注:本文中的System.Text.StringBuilder.AppendAndPopCharFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。