本文整理汇总了C#中System.IO.StringWriter.RemoveLast方法的典型用法代码示例。如果您正苦于以下问题:C# StringWriter.RemoveLast方法的具体用法?C# StringWriter.RemoveLast怎么用?C# StringWriter.RemoveLast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StringWriter
的用法示例。
在下文中一共展示了StringWriter.RemoveLast方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveLastTest
public void RemoveLastTest()
{
var writer = new StringWriter();
writer.Write("EKIEKIEKIPATENG ");
writer.RemoveLast(2);
const string expected = "EKIEKIEKIPATENG";
var actual = writer.ToString();
Assert.AreEqual(expected, actual);
}
示例2: ReadSection
public string ReadSection(ImapResponseReader reader)
{
var text = reader.CurrentLine;
var sn = Regex.Match(text, @"\d+").Value;
using (var sw = new StringWriter()) {
using (var sr = new StringReader(text)) {
var stack = new Stack<char>();
var isStarted = false;
var index = text.IndexOf("BODYSTRUCTURE");
var buffer = new char[index + 1];
sr.Read(buffer, 0, index);
while (true) {
if (isStarted) {
sw.Write(buffer[0]);
}
var count = sr.Read(buffer, 0, 1);
// end of string
if (count == 0) {
break;
}
// matching brace found
if (isStarted && stack.Count == 0) {
break;
}
if (buffer[0] == Characters.RoundOpenBracket) {
stack.Push(buffer[0]);
isStarted = true;
continue;
}
if (buffer[0] == Characters.RoundClosedBracket) {
stack.Pop();
continue;
}
}
// is a size appended to indicate multilined data? {####}
var sizeMatch = Regex.Match(reader.CurrentLine, @"\{\d+\}$");
if (sizeMatch.Success) {
// need to remove {####} from end of string
sw.RemoveLast(sizeMatch.Value.Length);
// Usually we could determine the amount of data to read from the size parameter at the end of the line
// unfortunately here the number contained seems to be completely arbitrary since it never fits, coming from 1und1 its always 107, no matter what follows.
// The 'only' thing I can be sure of when determining the amount of data to append is that it has to end with a closing bracket, no matter what.
while (true) {
reader.ReadNextLine();
var line = reader.CurrentLine;
sizeMatch = Regex.Match(reader.CurrentLine, @"\{\d+\}$");
// cut trailing {###} expression if necessary
var normalizedLine = sizeMatch.Success ? line.Substring(0, line.Length - sizeMatch.Value.Length) : line;
// decode line since its usually encoded using QP or Base64
normalizedLine = TransferEncoder.DecodeHeaderIfNecessary(normalizedLine);
// append line to regular body struct
sw.Write(normalizedLine);
if (reader.CurrentLine.EndsWith(")")) {
break;
}
}
}
// we silently append the sequence number to the end of the body structure,
// the parser will ignore it, but we can read it later without having to split or change this string
sw.Write(Characters.Space);
sw.Write(sn);
return sw.ToString();
}
}
}
示例3: ToString
public override string ToString()
{
using (var sw = new StringWriter()) {
foreach (var value in Values) {
sw.Write(value);
sw.Write(Characters.Comma);
}
sw.RemoveLast(1);
return sw.ToString();
}
}