本文整理匯總了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();
}
示例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();
}