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


C# StringWriter.RemoveLast方法代码示例

本文整理汇总了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);
 }
开发者ID:pravse,项目名称:CommSample,代码行数:9,代码来源:StringWriterExtensionsTest.cs

示例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();
                }
            }
        }
开发者ID:pravse,项目名称:CommSample,代码行数:79,代码来源:BodyStructReader.cs

示例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();
     }
 }
开发者ID:pravse,项目名称:CommSample,代码行数:11,代码来源:SequenceSet.cs


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