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


C# StringReader.Read方法代码示例

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


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

示例1: ReadNextNumber

    int ReadNextNumber(StringReader input)
    {
        string result = "";
        while (input.Peek() >= 0) {
            char c = (char)input.Read();
            if (c == '\r') {
                input.Read();
                break;
            } else if (c == '\n' || c == ' ' || c == '\t') {
                break;
            }

            result += c;
        }

        if (result == "") {
            return -9999;
        } else {
            return int.Parse(result);
        }
    }
开发者ID:mbonner4th,项目名称:TeamInfinity,代码行数:21,代码来源:LevelManager.cs

示例2: ReadReadsExactlyNCharacters

        public void ReadReadsExactlyNCharacters(string input, string expected1, string expected2)
        {
            // Arrange
            var stringReader = new StringReader(input);

            // Act
            string actual1 = stringReader.Read(n: 5);
            string actual2 = stringReader.Read(n: 5);

            // Assert
            Assert.Equal(expected1, actual1);
            Assert.Equal(expected2, actual2);
        }
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:13,代码来源:StringReaderFacts.cs

示例3: ReadReadsCharacter

        public void ReadReadsCharacter(string input, char expected1, char expected2)
        {
            // Arrange
            var stringReader = new StringReader(input);

            // Act
            char actual1 = stringReader.Read();
            char actual2 = stringReader.Read();

            // Assert
            Assert.Equal(expected1, actual1);
            Assert.Equal(expected2, actual2);
        }
开发者ID:NorimaConsulting,项目名称:kudu,代码行数:13,代码来源:StringReaderFacts.cs

示例4: Start

    void Start()
    {
        cameraController = Camera.main.GetComponent<CameraController>();

        try {
            using (StreamReader sr = new StreamReader(Application.dataPath + "/Levels/" + "01.txt")) {
                string line;
                int gridY = gridHeight-1;

                while ((line = sr.ReadLine()) != null) {
                    // if line.Lenght != gridWidth-1 and other conditions
                    char[] chars = new char[gridWidth];
                    using (StringReader sgr = new StringReader(line)) {
                        sgr.Read(chars, 0, gridWidth);
                        int gridX = 0;
                        foreach (char c in chars) {
                            CreateInstance(c, gridX, gridY);
                            gridX++;
                        }
                    }
                    gridY--;
                }
            }
        } catch (Exception e) {
            Debug.LogException(e);
        }
    }
开发者ID:vkuzma,项目名称:loderunner,代码行数:27,代码来源:GameController.cs

示例5: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strValue = String.Empty;
		Char[] chArr = new Char[]{
			Char.MinValue
			,Char.MaxValue
			,'\t'
			,' '
			,'$'
			,'@'
			,'#'
			,'\0'
			,'\v'
			,'\''
			,'\u3190'
			,'\uC3A0'
			,'A'
			,'5'
			,'\uFE70' 
			,'-'
			,';'
			,'\u00E6'
			,'\n'
			,'\v'
		};
		try {
			StringBuilder sb = new StringBuilder(40);
			StringWriter sw = new StringWriter(sb);
			StringReader sr;
			for(int i = 0 ; i < chArr.Length ; i++)
				sb.Append(chArr[i]);
			sw.Write(sb.ToString());
			sr = new StringReader(sw.GetStringBuilder().ToString());
			Int32 tmp = 0;
			for(int i = 0 ; i < chArr.Length ; i++) {
				iCountTestcases++;
				if((tmp = sr.Read()) != (Int32)chArr[i]) {
					iCountErrors++;
					printerr( "Error_298vc_"+i+"! Expected=="+(Int32)chArr[i]+", got=="+tmp);
				}
			}
		} catch (Exception exc) {
			iCountErrors++;
			printerr( "Error_298yg! Unexpected exception thrown, exc=="+exc.ToString());
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:59,代码来源:co5559write_str.cs

示例6: YourMethod

    public String YourMethod(String texto, String numero)
    {
        try
        {
            int n = int.Parse(numero);
            char ch = 'p';
            String s = "<p>";
            StringReader reader;
            reader = new StringReader(texto);
            while (reader.Peek() > -1)
            {
                for (int i = 0; i < n; ++i)
                {
                        if (i == n - 1)
                        {
                            if ((char)reader.Peek() != ' ')
                            {
                                ch = (char)reader.Read();
                                s += ch;
                            }
                        }
                        else {
                            ch = (char)reader.Read();
                            s += ch;
                        }
                    }
                    if (reader.Peek() > -1 && (char)reader.Peek() != ' ')
                {
                    s += "-";
                }
                else
                {
                    reader.Read();
                }
                s += "\n</p><p>";
            }
            return s;
        }
        catch (FormatException)
        {

        }
        return "error";

    }
开发者ID:alexandergg,项目名称:Azure-Website,代码行数:45,代码来源:page.aspx.cs

示例7: runTest

	public bool runTest()
	{
		int iCountErrors = 0;
		int iCountTestcases = 0;
        String strTemp = String.Empty ;
        Char[] cArr = new Char[10] ;
        StringBuilder sb = new StringBuilder(40);
        StringWriter sw = new StringWriter(sb);
        StringReader sr;
        iCountTestcases++;
        bool[] bArr = new bool[]{  true,true,true,true,true,false,false,false,false,false};
		try {
			for(int i = 0 ; i < bArr.Length ; i++)
				sw.WriteLine(bArr[i]);
			sr = new StringReader(sw.GetStringBuilder().ToString());
			for(int i = 0 ; i < bArr.Length ; i++) {
                sr.Read(cArr, 0, bArr[i].ToString().Length+System.Environment.NewLine.Length);
				if(new String(cArr, 0, bArr[i].ToString().Length) != bArr[i].ToString()) {
					iCountErrors++;
					printerr( "Error_298vc_"+i+"! Expected=="+bArr[i].ToString()+", got=="+new String(cArr));
				}
			}
		} catch (Exception exc) {
			iCountErrors++;
			printerr( "Error_298yg! Unexpected exception thrown, exc=="+exc.ToString());
		}
        iCountTestcases++;
        bArr = new bool[10000];
        for(int i = 0 ; i < bArr.Length ; i++)
            bArr[i] = Convert.ToBoolean(rand.Next(0,2));
		try {
            sb.Length = 0;
			for(int i = 0 ; i < bArr.Length ; i++)
				sw.WriteLine(bArr[i]);
			sr = new StringReader(sw.GetStringBuilder().ToString());
			for(int i = 0 ; i < bArr.Length ; i++) {
                sr.Read(cArr, 0, bArr[i].ToString().Length+System.Environment.NewLine.Length);
                if(new String(cArr, 0, bArr[i].ToString().Length) != bArr[i].ToString()) {
					iCountErrors++;
					printerr( "Error_57485_"+i+"! Expected=="+bArr[i].ToString()+", got=="+new String(cArr));
				}
			}
		} catch (Exception exc) {
			iCountErrors++;
			printerr( "Error_43432! Unexpected exception thrown, exc=="+exc.ToString());
		}
        if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL! iCountErrors=="+iCountErrors.ToString() );
			return false;
		}
	}
开发者ID:ArildF,项目名称:masters,代码行数:57,代码来源:co9402writeline_bool.cs

示例8: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			StringReader sr;
			strLoc = "Loc_98yg7";
			iCountTestcases++;
			try {		
                sr = new StringReader(null);
                String strTemp = sr.ReadToEnd();
				iCountErrors++;
				printerr( "Error_18syx! StringReader should only hold null");
				sr.ReadLine();
				sr.Peek();
				sr.Read();
				sr.Close();
			} catch (ArgumentNullException exc) {
				printinfo("Expected exception thrown, exc=="+exc.Message);
			}catch (Exception exc) {
				iCountErrors++;
				printerr("Error_109xu! Unexpected exception thrown, exc=="+exc.ToString());
			}
			strLoc = "Loc_4790s";
			sr = new StringReader(String.Empty);
			iCountTestcases++;
			if(!sr.ReadToEnd().Equals(String.Empty)) {
				iCountErrors++;
				printerr( "Error_099xa! Incorrect construction");
			}		   		 
			strLoc = "Loc_8388x";
			sr = new StringReader("Hello\0World");
			iCountTestcases++;
			if(!sr.ReadToEnd().Equals("Hello\0World")) {
				iCountErrors++;
				printerr( "Error_1099f! Incorrect construction");
			}
		} catch (Exception exc_general ) {			
			++iCountErrors;
			Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:56,代码来源:co5566ctor_str.cs

示例9: HtmlLexicalAnalyzer

    // ---------------------------------------------------------------------
    //
    // Constructors
    //
    // ---------------------------------------------------------------------

    #region Constructors

    /// <summary>
    /// initializes the _inputStringReader member with the string to be read
    /// also sets initial values for _nextCharacterCode and _nextTokenType
    /// </summary>
    /// <param name="inputTextString">
    /// text string to be parsed for xml content
    /// </param>
    internal HtmlLexicalAnalyzer(string inputTextString)
    {
        _inputStringReader = new StringReader(inputTextString);
        _nextCharacterCode = 0;
        _nextCharacter = ' ';
        _lookAheadCharacterCode = _inputStringReader.Read();
        _lookAheadCharacter = (char)_lookAheadCharacterCode;
        _previousCharacter = ' ';
        _ignoreNextWhitespace = true;
        _nextToken = new StringBuilder(100);
        _nextTokenType = HtmlTokenType.Text;
        // read the first character so we have some value for the NextCharacter property
        this.GetNextCharacter();
    }
开发者ID:AbabeiAndrei,项目名称:WProject,代码行数:29,代码来源:HtmlLexicalAnalyzer.cs

示例10: ConfigFilesFilter

        public ConfigFilesFilter(RandoopConfiguration config)
        {
            if (config == null) throw new ArgumentNullException("config");

            Common.StringReader r = new StringReader();

            foreach (FileName path in config.forbid_typesFiles)
                forbid_types.AddRange(r.Read(path.fileName));

            foreach (FileName path in config.forbid_membersFiles)
                forbid_members.AddRange(r.Read(path.fileName));

            foreach (FileName path in config.forbid_fieldsFiles)
                forbid_fields.AddRange(r.Read(path.fileName));

            foreach (FileName path in config.require_typesFiles)
                require_types.AddRange(r.Read(path.fileName));

            foreach (FileName path in config.require_membersFiles)
                require_members.AddRange(r.Read(path.fileName));

            foreach (FileName path in config.require_fieldsFiles)
                require_fields.AddRange(r.Read(path.fileName));
        }
开发者ID:SJMakin,项目名称:Randoop.NET,代码行数:24,代码来源:ReflectionFilters.cs

示例11: Escape

		/// <summary>Swaps e.g. < with &gt; so the text won't get treated like xml/html.</summary>
		/// <param name="xml">The xml to escape.</param>
		/// <returns>The escaped string.</returns>
		public static string Escape(string xml){
			StringReader reader=new StringReader(xml);
			System.Text.StringBuilder result=new System.Text.StringBuilder();
			
			while(reader.More()){
				char character=reader.Read();
				if(character=='<'){
					result.Append("&lt;");
				}else if(character=='>'){
					result.Append("&gt;");
				}else if(character=='&'){
					result.Append("&amp;");
				}else{
					result.Append(character);
				}
			}
			return result.ToString();
		}
开发者ID:KMarshland,项目名称:ChildrensHospitalApp,代码行数:21,代码来源:Text.cs

示例12: parseConstant

    // This method checks if every char of the String is a digit
    // This returns the boolean result
    private bool parseConstant(String constant)
    {
        bool exp = false;
        StringReader reader = new StringReader(constant);
        while (reader.Peek() != -1)
        {
            var digit = (char)reader.Read();
            if (isDigit(digit))
            {
                exp = true;
            }
            else
            {
                exp = false;
                break;
            }

        }
        reader.Close();
        return exp;
    }
开发者ID:JericoPablo,项目名称:Informatik-3-Gruppe-10,代码行数:23,代码来源:Parser.cs

示例13: UrlEncode

		/// <summary>
		/// UrlEncodes a string without the requirement for System.Web
		/// </summary>
		/// <param name="String"></param>
		/// <returns></returns>
		public static string UrlEncode(string InputString)
		{
			StringReader sr = new StringReader(InputString);
			StringBuilder sb = new StringBuilder(InputString.Length);

			while (true)
			{
				int Value = sr.Read();
				if (Value == -1)
					break;
				char CharValue = (char)Value;

				if (CharValue >= 'a' && CharValue <= 'z' ||
					CharValue >= 'A' && CharValue <= 'Z' ||
					CharValue >= '0' && CharValue <= '9')
					sb.Append(CharValue);
				else if (CharValue == ' ')
					sb.Append("+");
				else
					sb.AppendFormat("%{0:X2}", Value);
			}

			return sb.ToString();
		}
开发者ID:haimon74,项目名称:KanNaim,代码行数:29,代码来源:wwUtils.cs

示例14: 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:haimon74,项目名称:KanNaim,代码行数:32,代码来源:wwUtils.cs

示例15: sscanf

    static public int sscanf(String stream, String format, Object[] results)
    {
        int fieldsRead = 0;
        int resultsIndex = 0;
        int formatIndex = 0;
        char fieldType = '\0';
        char charRead = '\0';
        bool readingField = false;
        bool eatWhiteSpace = false;
        StringReader srStream = new StringReader(stream);

        while (formatIndex < format.Length)
        {
            if (Char.IsWhiteSpace((char)format[formatIndex]))
            {
                eatWhiteSpace = true;
                formatIndex++;
                continue;
            }
            while (eatWhiteSpace)
            {
                if (!Char.IsWhiteSpace((char)srStream.Peek()))
                {
                    eatWhiteSpace = false;
                    break;
                }
                srStream.Read();
            }
            if ('%' == format[formatIndex])  //If we found a scan field type
            {
                StringBuilder sb = new StringBuilder();
                ++formatIndex;
                fieldType = format[formatIndex++];
                readingField = true;
                charRead = (char)srStream.Read();

                while (readingField)
                {
                    if (-1 == (short)charRead)
                    {
                        readingField = false;
                    }

                    sb.Append(charRead);

                    int intCharRead = srStream.Peek();
                    unchecked
                    {
                        charRead = (char)intCharRead;
                    }
                    if (Char.IsWhiteSpace(charRead) || ('c' == fieldType) || (-1 == intCharRead))
                    {
                        readingField = false;
                        fieldsRead++;

                        switch (fieldType)
                        {
                            case 'c':
                                results[resultsIndex++] = sb.ToString()[0];
                                break;
                            case 'd':
                            case 'i':
                                int parsedInt;
                                parsedInt = int.Parse(sb.ToString());
                                results[resultsIndex++] = parsedInt;
                                break;
                            case 'f':
                                double parsedDouble;
                                parsedDouble = double.Parse(sb.ToString());
                                results[resultsIndex++] = parsedDouble;
                                break;
                            case 's':
                                results[resultsIndex++] = sb.ToString();
                                break;
                        }
                        continue;
                    }
                    charRead = (char)srStream.Read();
                }
            }
        }

        return fieldsRead;
    }
开发者ID:akarpov89,项目名称:coreclr,代码行数:84,代码来源:utility.cs


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