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


C# StringReader.Read方法代码示例

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


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

示例1: UrlDecode

        /// <summary>
        /// UrlDecodes a string without requiring System.Web
        /// </summary>
        /// <param name="InputString">String to decode.</param>
        /// <returns>decoded string</returns>
        public static string UrlDecode(string InputString)
        {
            char temp = ' ';
            StringReader sr = new StringReader(InputString);
            StringBuilder sb = new StringBuilder( InputString.Length );

            while (true)
            {
                int lnVal = sr.Read();
                if (lnVal == -1)
                    break;
                char TChar = (char) lnVal;
                if (TChar == '+')
                    sb.Append(' ');
                else if(TChar == '%')
                {
                    // *** read the next 2 chars and parse into a char
                    temp = (char) Int32.Parse(((char) sr.Read()).ToString() +  ((char) sr.Read()).ToString(),
                                                   System.Globalization.NumberStyles.HexNumber);
                    sb.Append(temp);
                }
                else
                    sb.Append(TChar);
            }

            return sb.ToString();
        }
开发者ID:liqueflies,项目名称:pigeoncms,代码行数:32,代码来源:wwHttpUtils.cs

示例2: Factor

 /* The Method Factor checks if the next Element in the String is an Element of the Lists
 * varibles or digit or read.peek() is -1 (then theres no next element in the string) if not it has to be a "(" otherwise the expression is false
 */
 private void Factor(StringReader reader)
 {
     if (variables.Contains((char)reader.Peek()))
     {
         reader.Read();
         return;
     }
     else if (digit.Contains((char)reader.Peek()))
     {
         reader.Read();
         Constant(reader);
         return;
     }
     else if ((char)reader.Peek() == '(')
     {
         reader.Read();
         Expression(reader);
         if ((char)reader.Peek() == ')')
         {
             reader.Read();
             return;
         }
         else
         {
             throw new ParseError("\")\" expected");
         }
     }
     else if (reader.Peek() == -1) // wenn der reader -1 als nächstes zeichen sieht dann ist string zu ende gelesen
     {
         return;
     }
     else throw new ParseError("invalid factor in "+ expressionString);
 }
开发者ID:MarvinWeiss,项目名称:Inf3_Gruppe4_WS15,代码行数:36,代码来源:Parser.cs

示例3: Parse

 public string Parse(string message)
 {
     StringBuilder sb = new StringBuilder();
     StringReader sr = new StringReader(message);
     char[] buf = new char[1];
     while (sr.Read(buf, 0, 1) > 0)
     {
         if (buf[0] == '&')
         {
             if (sr.Read(buf, 0, 1) > 0)
             {
                 if (buf[0] == '&')
                     sb.Append('&');
                 else
                     sb.Append(GetColor(buf[0]));
             }
             else
                 break;
         }
         else
         {
             sb.Append(buf[0]);
         }
     }
     return sb.ToString();
 }
开发者ID:dogbert69,项目名称:fallout-mud,代码行数:26,代码来源:AsciiOutputParser.cs

示例4: format

        public string format(string text)
        {
            reader = new StringReader(text);

            int cache;

            while((cache = reader.Peek()) != -1)
            {
                if(cache == '%')
                {
                    reader.Read();
                    string c;
                    if((c = controlIdentify()) != null)
                    {
                        builder.Append(c);
                    }else
                    {
                        break;
                    }
                }
                else
                {
                    builder.Append((char)reader.Read());
                }
            }

            return builder.ToString();
        }
开发者ID:Cowscript,项目名称:CowScript,代码行数:28,代码来源:StringFormater.cs

示例5: Main

        static void Main(string[] args)
        {
            StringWriter w = new StringWriter();
            w.WriteLine("Sing a song of {0} pence", 6);
            string s = "A pocket full of rye";
            w.Write(s);
            w.Write(w.NewLine);
            w.Write(string.Format(4 + " and " + 20 + " blackbirds"));
            w.Write(new StringBuilder(" baked in a pie"));
            w.WriteLine();
            Console.WriteLine(w);

            StringBuilder sb = w.GetStringBuilder();
            int i = sb.Length;
            sb.Append("The birds began to sing");
            sb.Insert(i, "when the pie was opened\n");
            sb.AppendFormat("\nWasn't that a {0} to set before the king", "dainty dish");
            Console.WriteLine(w);

            Console.WriteLine();
            StringReader r = new StringReader(w.ToString());
            string t = r.ReadLine();
            Console.WriteLine(t);
            Console.Write((char)r.Read());
            char[] ca = new char[37];
            r.Read(ca, 0, 19);
            Console.Write(ca);
            Console.WriteLine(r.ReadToEnd());

            r.Close();
            w.Close();
            Console.ReadLine();
        }
开发者ID:GGammu,项目名称:InsideCSharp,代码行数:33,代码来源:Program.cs

示例6: Scan

        public IEnumerable<Token> Scan(string expression)
        {
            _reader = new StringReader(expression);

            var tokens = new List<Token>();
            while (_reader.Peek() != -1)
            {
                var c = (char)_reader.Peek();
                if (Char.IsWhiteSpace(c))
                {
                    _reader.Read();
                    continue;
                }

                if (Char.IsDigit(c))
                {
                    var nr = ParseNumber();
                    tokens.Add(new NumberConstantToken(nr));
                }
                else if (c == '-')
                {
                    tokens.Add(new MinusToken());
                    _reader.Read();
                }
                else if (c == '+')
                {
                    tokens.Add(new PlusToken());
                    _reader.Read();
                }
                else
                    throw new Exception("Unknown character in expression: " + c);
            }

            return tokens;
        }
开发者ID:santosh-mnrec,项目名称:Compiler,代码行数:35,代码来源:PlusMinusTokenizer.cs

示例7: RemoveSpaces2

        public static string RemoveSpaces2(string value, int length)
        {
            var stringBuilder = new StringBuilder();
            using (var stringReader = new StringReader(value))
            {
                while (stringReader.Peek() != -1)
                {
                    var ch = (char)stringReader.Peek();
                    if (char.IsWhiteSpace(ch))
                    {
                        while (char.IsWhiteSpace(ch))
                        {
                            stringReader.Read();
                            ch = (char)stringReader.Peek();
                        }

                        if (stringBuilder.Length != 0 && stringBuilder.Length < length)
                        {
                            stringBuilder.Append("%20");
                        }
                    }
                    else
                    {
                        stringBuilder.Append((char)stringReader.Read());
                    }
                }
            }

            return stringBuilder.ToString();
        }
开发者ID:TerraVenil,项目名称:Algorithms,代码行数:30,代码来源:StringRemoveSpaces.cs

示例8: AddExpression

        public void AddExpression(string name, string regex)
        {
            using (var stream = new StringReader(InfixToPostfix.Convert(regex)))
            {
                while (stream.Peek() != -1)
                {
                    var c = (char) stream.Read();
                    switch (c)
                    {
                        case '.': _stack.Concatenate(); break;
                        case '|': _stack.Unite(); break;
                        case '*': _stack.Iterate(); break;
                        case '+': _stack.AtLeast(); break;
                        case '?': _stack.Maybe(); break;
                        default:
                            var a = new NFA<char>();
                            a.AddTransition(a.Start, new State(), c == '\\' ? Escape((char) stream.Read()) : c);
                            _stack.Push(a);
                            break;
                    }
                }

                var top = _stack.Peek();
                top.LastAdded.Final = true;
                top.SetName(top.LastAdded, name);
            }
        }
开发者ID:surenkov,项目名称:UCP,代码行数:27,代码来源:RegexEngine.cs

示例9: TransformCssFile

        // The parsing logic is based on http://www.w3.org/TR/CSS2/syndata.html.
        internal static string TransformCssFile( string sourceCssText )
        {
            sourceCssText = RegularExpressions.RemoveMultiLineCStyleComments( sourceCssText );

            var customElementsDetected = from Match match in Regex.Matches( sourceCssText, customElementPattern ) select match.Value;
            customElementsDetected = customElementsDetected.Distinct();
            var knownCustomElements = CssPreprocessingStatics.Elements.Select( ce => reservedCustomElementPrefix + ce.Name );
            var unknownCustomElements = customElementsDetected.Except( knownCustomElements ).ToList();
            if( unknownCustomElements.Any() ) {
                throw new MultiMessageApplicationException(
                    unknownCustomElements.Select( e => "\"" + e + "\" begins with the reserved custom element prefix but is not a known custom element." ).ToArray() );
            }

            using( var writer = new StringWriter() ) {
                var buffer = new StringBuilder();
                using( var reader = new StringReader( sourceCssText ) ) {
                    char? stringDelimiter = null;
                    while( reader.Peek() != -1 ) {
                        var c = (char)reader.Read();

                        // escaped quote, brace, or other character
                        if( c == '\\' ) {
                            buffer.Append( c );
                            if( reader.Peek() != -1 )
                                buffer.Append( (char)reader.Read() );
                        }

                        // string delimiter
                        else if( !stringDelimiter.HasValue && ( c == '\'' || c == '"' ) ) {
                            buffer.Append( c );
                            stringDelimiter = c;
                        }
                        else if( stringDelimiter.HasValue && c == stringDelimiter ) {
                            buffer.Append( c );
                            stringDelimiter = null;
                        }

                        // selector delimiter
                        else if( !stringDelimiter.HasValue && ( c == ',' || c == '{' ) ) {
                            writer.Write( getTransformedSelector( buffer.ToString() ) );
                            writer.Write( c );
                            buffer = new StringBuilder();
                        }
                        else if( !stringDelimiter.HasValue && c == '}' ) {
                            writer.Write( buffer.ToString() );
                            writer.Write( c );
                            buffer = new StringBuilder();
                        }

                        // other character
                        else
                            buffer.Append( c );
                    }
                }
                writer.Write( buffer.ToString() );
                return writer.ToString();
            }
        }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:59,代码来源:CssPreprocessor.cs

示例10: StringToByteArray

 // Methods
 private byte[] StringToByteArray(string hex)
 {
     int NumberChars = hex.Length / 2;
     byte[] bytes = new byte[NumberChars];
     using (var sr = new StringReader(hex))
         for (int i = 0; i < NumberChars; i++)
             bytes[i] = Convert.ToByte(new string(new char[2] { (char)sr.Read(), (char)sr.Read() }), 16);
     return bytes;
 }
开发者ID:XeClutch,项目名称:Cheat-Engine-For-Xbox-360,代码行数:10,代码来源:ChangeValueForm.cs

示例11: Format

        /// <summary>
        /// Gets a string representation of a code element using the specified
        /// format.
        /// </summary>
        /// <param name="format">The format.</param>
        /// <param name="codeElement">The code element.</param>
        /// <returns>Formatted string representation of the code element.</returns>
        public static string Format(string format, ICodeElement codeElement)
        {
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            else if (codeElement == null)
            {
                throw new ArgumentNullException("codeElement");
            }

            StringBuilder formatted = new StringBuilder(format.Length*2);
            StringBuilder attributeBuilder = null;
            bool inAttribute = false;

            using (StringReader reader = new StringReader(format))
            {
                int data = reader.Read();
                while (data > 0)
                {
                    char ch = (char) data;

                    if (ch == ConditionExpressionParser.ExpressionPrefix &&
                        (char) (reader.Peek()) == ConditionExpressionParser.ExpressionStart)
                    {
                        reader.Read();
                        attributeBuilder = new StringBuilder(16);
                        inAttribute = true;
                    }
                    else if (inAttribute)
                    {
                        if (ch == ConditionExpressionParser.ExpressionEnd)
                        {
                            ElementAttributeType elementAttribute = (ElementAttributeType) Enum.Parse(
                                typeof (ElementAttributeType), attributeBuilder.ToString());

                            string attribute = GetAttribute(elementAttribute, codeElement);
                            formatted.Append(attribute);
                            attributeBuilder = new StringBuilder(16);
                            inAttribute = false;
                        }
                        else
                        {
                            attributeBuilder.Append(ch);
                        }
                    }
                    else
                    {
                        formatted.Append(ch);
                    }

                    data = reader.Read();
                }
            }

            return formatted.ToString();
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:64,代码来源:ElementUtilities.cs

示例12: GetByteArrayFromHexadecimalRepresentation

 public static byte[] GetByteArrayFromHexadecimalRepresentation(string hexadecimal_s)
 {
     hexadecimal_s = GetNormalizedHexadecimalRepresentation(hexadecimal_s);
     int cn = hexadecimal_s.Length / 2;
     byte[] bytes = new byte[cn];
     StringReader sr = new StringReader(hexadecimal_s);
     for (int i = 0; i < cn; i++) bytes[i] = Convert.ToByte(new string(new char[2] { (char)sr.Read(), (char)sr.Read() }), 16);
     return bytes;
 }
开发者ID:sergeystoyan,项目名称:FhrCliverHost,代码行数:9,代码来源:StringByteRoutines.cs

示例13: HexStringToByteArray

 public static byte[] HexStringToByteArray(String hexString)
 {
     int NumberChars = hexString.Length / 2;
     byte[] bytes = new byte[NumberChars];
     StringReader sr = new StringReader(hexString);
     for (int i = 0; i < NumberChars; i++)
         bytes[i] = Convert.ToByte(new string(new char[2] { (char)sr.Read(), (char)sr.Read() }), 16);
     sr.Dispose();
     return bytes;
 }
开发者ID:Kreyl,项目名称:nute,代码行数:10,代码来源:Command.cs

示例14: ReadSection

        public string ReadSection(ImapResponseReader reader)
        {
            var text = reader.CurrentLine;
            using (var sw = new StringWriter()) {
                using (var sr = new StringReader(text)) {
                    var stack = new Stack<char>();

                    var isQuoted = false;
                    var isStarted = false;
                    var index = text.IndexOf("ENVELOPE");
                    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;
                        }

                        if (isStarted && stack.Count == 0) {
                            break;
                        }

                        if (buffer[0] == Characters.Quote) {
                            isQuoted = !isQuoted;
                            continue;
                        }

                        // braces inside a quoted string need to be ignored
                        if (isQuoted) {
                            continue;
                        }

                        // matching brace found
                        if (buffer[0] == Characters.RoundOpenBracket) {
                            stack.Push(buffer[0]);
                            isStarted = true;
                            continue;
                        }

                        if (buffer[0] == Characters.RoundClosedBracket) {
                            stack.Pop();
                            continue;
                        }
                    }
                    return sw.ToString();
                }
            }
        }
开发者ID:pravse,项目名称:CommSample,代码行数:55,代码来源:EnvelopeReader.cs

示例15: ReadNormally

        public void ReadNormally()
        {
            StringReader reader = new StringReader("Test");
            ScanningTextReader scanningReader = new ScanningTextReader(reader);

            Assert.AreEqual('T', reader.Read());
            Assert.AreEqual('e', reader.Read());
            Assert.AreEqual('s', reader.Read());
            Assert.AreEqual('t', reader.Read());
            Assert.AreEqual(-1, reader.Read());
        }
开发者ID:iSynaptic,项目名称:iSynaptic.Commons,代码行数:11,代码来源:ScanningTextReaderTests.cs


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