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