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


C# StreamReader.Read方法代码示例

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


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

示例1: GetMessageFromWeb

 public static string GetMessageFromWeb(string strURL)
 {
     System.Text.StringBuilder sbuBuilder;
     // Creates an HttpWebRequest with the specified URL. 
     HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
     // Sends the HttpWebRequest and waits for the response.            
     HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
     // Gets the stream associated with the response.
     Stream receiveStream = myHttpWebResponse.GetResponseStream();
     Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
     // Pipes the stream to a higher level stream reader with the required encoding format. 
     StreamReader readStream = new StreamReader(receiveStream, encode);
     sbuBuilder = new System.Text.StringBuilder();
     Char[] read = new Char[READ_CHUNK_SIZE];
     // Reads 256 characters at a time.    
     int count = readStream.Read(read, 0, READ_CHUNK_SIZE);
     while (count > 0)
     {
         sbuBuilder.Append(read);
         if (count < READ_CHUNK_SIZE)
         {
             sbuBuilder.Remove(sbuBuilder.Length - (READ_CHUNK_SIZE - count), READ_CHUNK_SIZE - count);
         }
         count = readStream.Read(read, 0, READ_CHUNK_SIZE);
     }
     myHttpWebResponse.Close();
     readStream.Close();
     return sbuBuilder.ToString();
 }
开发者ID:0huah0,项目名称:csharp-samples,代码行数:29,代码来源:Emailer.cs

示例2: Main

    static void Main()
    {
        Console.WriteLine("This program extracts from given XML file all the text without the tags.");
        Console.Write("Result: ");
        using (StreamReader read = new StreamReader("..//..//XML.txt"))
        {
            int charactrer = read.Read();
            bool start = false;

            while (charactrer != -1)
            {
                if (charactrer == '>')
                {
                    start = true;
                }
                else if (charactrer == '<' || charactrer == '\r' || charactrer == '\n')
                {
                    start = false;
                }
                if (start && charactrer != '>')
                {
                    Console.Write((char)charactrer);
                }
                charactrer = read.Read();
            }
        }
        Console.WriteLine();
        Console.WriteLine("You can find all results and text files in the folders of the different projects!");
    }
开发者ID:ivanvasilev,项目名称:Telerik-Academy-Homeworks,代码行数:29,代码来源:10.+Extract+text+from+XML.cs

示例3: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        //make call to external url and display results
        WebResponse result = null;
        string output = "";

        WebRequest req = WebRequest.Create(ServletCallUrl);
        result = req.GetResponse();
        Stream ReceiveStream = result.GetResponseStream();
        Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
        StreamReader sr = new StreamReader(ReceiveStream, encode);
        Char[] read = new Char[256];
        int count = sr.Read(read, 0, read.Length);
        while (count > 0)
        {
            String str = new String(read, 0, count);
            output += str;
            count = sr.Read(read, 0, read.Length);
        }

        if (result != null)
        {
            result.Close();
        }

        Response.Write(output);
    }
开发者ID:pingshuibing,项目名称:orange-1,代码行数:27,代码来源:Proxy.aspx.cs

示例4: Main

    static void Main()
    {
        char tempString = new char();
        int boundary = new int();
        string text = string.Empty;

        using (StreamReader rdr = new StreamReader(@"..\..\Files\someFile.xml"))
        {
             boundary = rdr.Read();
            while ('~' - tempString > 0)
            {
                if (tempString == '>')
                {
                    tempString = (char)rdr.Read();
                    while ((tempString != '<') && ('~' - tempString > 0))
                    {
                        if (tempString != '\n' && tempString != '\r' )
                        {
                            text += (char)tempString;
                            tempString = (char)rdr.Read();
                        }
                        else
                        {
                            tempString = (char)rdr.Read();
                        }
                    }
                    Console.WriteLine(text.Trim());
                    text = string.Empty;
                }
                boundary = rdr.Read();
                tempString = (char)boundary;
            }
        }
    }
开发者ID:vanjiii,项目名称:TelerikAcademy,代码行数:34,代码来源:ExtrackTextFromXML.cs

示例5: Main

 static void Main()
 {
     List<string> text = new List<string>();
     StringBuilder build = new StringBuilder();
     using (StreamReader file = new StreamReader("../../text.txt"))
     {
         int tag=' ';
         for (int line; (line = file.Read()) != -1; )
         {
             if (tag == '>' && line != '<')
             {
                 while (line != '<' && line != -1)
                 {
                     build.Append((char)line);
                     line = file.Read();
                 }
                 text.Add(build.ToString());
                 build.Clear();
             }
             tag = line;
         }
     }
     for (int i = 0; i < text.Count; i++)
     {
         Console.Write(text[i]);
     }
     Console.WriteLine();
 }
开发者ID:vstoyanov88,项目名称:TelerikAcademy,代码行数:28,代码来源:TextWithoutTags.cs

示例6: Main

    static void Main()
    {
        try
        {
            using (StreamReader reader = new StreamReader(@"../../../example.xml"))
            {
                for (int i; (i = reader.Read()) != -1; )
                {
                    if (i == '>')
                    {
                        string text = String.Empty;
                        int j = reader.Read();
                        while ((j != -1) && (j != '<'))
                        {
                            text += (char)j;
                            j = reader.Read();
                        }
                        if (!string.IsNullOrEmpty(text))
                        {
                            Console.WriteLine(text);
                        }

                    }
                }
            }
        }
        catch (IOException ioEx)
        {
            Console.WriteLine(ioEx.Message);
        }
    }
开发者ID:kirilt7,项目名称:TelerikAcademyHomeworks,代码行数:31,代码来源:Program.cs

示例7: Main

    static void Main()
    {
        using (StreamReader read = new StreamReader("..//..//XML.txt"))
        {
            int charactrer = read.Read();
            bool start = false;

            while (charactrer != -1)
            {
                if (charactrer == '>')
                {
                    start = true;
                }
                else if (charactrer == '<' || charactrer == '\r' || charactrer == '\n')
                {
                    start = false;
                }
                if (start && charactrer != '>')
                {
                    Console.Write((char)charactrer);
                }
                charactrer = read.Read();
            }
        }
    }
开发者ID:NikolaiMishev,项目名称:Telerik-Academy,代码行数:25,代码来源:10.+Extract+text+from+XML.cs

示例8: RespCallback

    private static void RespCallback(IAsyncResult ar)
    {
        HttpWebRequest req;
        HttpWebResponse resp;
        int BytesRead;
        StreamReader Reader;
        StringWriter Writer;

        req=(HttpWebRequest)(Object)ar;
        resp=(HttpWebResponse)req.EndGetResponse(ar);

        BytesRead=0;
        char[] Buffer=new char[MAX];

        Reader=new StreamReader(resp.GetResponseStream(),System.Text.Encoding.UTF8);
        Writer=new StringWriter();

        BytesRead=Reader.Read(Buffer,0,MAX);
        while(BytesRead!=0)
        {
            Writer.Write(Buffer,0,MAX);
            BytesRead=Reader.Read(Buffer,0,MAX);
        }

        Console.WriteLine("Message="+Writer.ToString());
    }
开发者ID:ShiJess,项目名称:CompanyStudy,代码行数:26,代码来源:GetURLAsync.cs

示例9: Main

    static void Main()
    {
        using (StreamReader input = new StreamReader("../../DelPrefix.txt"))

                for (int i; (i = input.Read()) != -1; )
                {
                    if (i == 'M')
                    {
                        string text = String.Empty;

                        while ((i = input.Read()) != -1 && i != 'M') text += (char)i;

                        if (!String.IsNullOrWhiteSpace(text)) Console.WriteLine(text.Trim());
                    }
                    if (i == 'o')
                    {
                        string text = String.Empty;

                        while ((i = input.Read()) != -1 && i != 'o') text += (char)i;

                        if (!String.IsNullOrWhiteSpace(text)) Console.WriteLine(text.Trim());
                    }
                    if (i == 'n')
                    {
                        string text = String.Empty;

                        while ((i = input.Read()) != -1 && i != 'n') text += (char)i;

                        if (!String.IsNullOrWhiteSpace(text)) Console.WriteLine(text.Trim());
                    }
                }
    }
开发者ID:martinangelos88,项目名称:CSharpProject,代码行数:32,代码来源:11.DelSpecificPrefix.cs

示例10: Main

    static void Main()
    {
        /* Write a program that extracts from given XML file all the text without the tags.
         * Example:
         * <?xml version="1.0"><student><name>Pesho</name><age>21</age><interests count="3"><interest> Games</instrest><interest>C#</instrest><interest> Java</instrest></interests></student>
         */

        string path = @"...\...\someXML.txt"; // manually created xml file

        using (StreamReader input = new StreamReader(path))
        {
            int ch;

            // Read until you reach the end of the document
            while ((ch = input.Read()) != -1) 
            {
                // Inside text
                if (ch == '>')
                {                    
                    string text = String.Empty;

                    // Read until you reach '<' or end of the doc
                    while ((ch = input.Read()) != -1 && ch != '<')
                    {
                        text += (char)ch;
                    }

                    if (!String.IsNullOrWhiteSpace(text)) // Exclude non-text strings such as white-space or empty
                    {
                        Console.WriteLine(text.Trim()); // Also remove leading and trailing white-space
                    }
                }
            }
        }
    }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:35,代码来源:ExtractTextFromXML.cs

示例11: Main

	public static int Main ()
	{
	#endif
		string s = @"Hola\";
		string d = "Hola\\";
		string e = @"Co""a";
		string f = "Co\"a";

		if (s != d)
			return 1;
		if (e != f)
			return 2;

		string g = "Hello\nworld";

		using (StreamReader sr = new StreamReader("test-74.cs")) {
			int i = sr.Read ();
			if (sr.Read () <= 13)
				g = g.Replace ("\n", "\r\n");
		}

		string h = @"Hello
world";
		if (g != h) 
			return 3;

		System.Console.WriteLine ("OK");
		return 0;
	}
开发者ID:nobled,项目名称:mono,代码行数:29,代码来源:test-74.cs

示例12: Main

    static void Main()
    {
        using (StreamReader reader = new StreamReader(@"..\..\this.xml"))
        {
            //reads text
            for (int i; (i = reader.Read()) != -1; )
            {
                //between > and <
                if (i == '>')
                {
                    string text = String.Empty;

                    while ((i = reader.Read()) != -1 && i != '<')
                    {
                        text += (char)i;
                    }
                    if (!String.IsNullOrWhiteSpace(text))
                    {
                        //removes all leading and trailing white-space characters
                        Console.WriteLine(text.Trim());
                    }
                }
            }
        }
    }
开发者ID:NK-Hertz,项目名称:Telerik-Academy-2014,代码行数:25,代码来源:ExtractFromXML.cs

示例13: Main

 static void Main()
 {
     StreamReader reader = new StreamReader(@"..\..\File 1.txt");
     using(reader)
     {
         StreamWriter writer = new StreamWriter(@"..\..\File 2.txt");
         using (writer)
         {
             int end;
             char currentChar = (char)(end = reader.Read());
             while (end != -1)
             {
                 if (currentChar == '>')
                 {
                     currentChar = (char)(end = reader.Read()); ;
                     while ((currentChar != '<') && (end !=-1))
                     {
                         writer.Write(currentChar);
                         currentChar = (char)(end = reader.Read());
                     }
                 }
                 currentChar = (char)(end = reader.Read());
             }
         }
     }
     Console.WriteLine("File is written!");
 }
开发者ID:July5,项目名称:Telerik-Academy,代码行数:27,代码来源:GetOnlyTextFromXMLTextFile.cs

示例14: Main

 static void Main(string[] args)
 {
     StreamReader reader = new StreamReader(@"..\..\InputFile.xml");
     using (reader)
     {
         bool outsideTheTags = false;
         int currentChar = reader.Read(); //reads the next char, returns int
         while (currentChar != -1) // currentChar = -1 in the end of the file
         {
             if (currentChar == 62) // if ">" we come out of the tags
             {
                 outsideTheTags = true;
                 currentChar = reader.Read();
             }
             if (currentChar == 60) // if "<" we come in the tags
             {
                 outsideTheTags = false;
                 currentChar = reader.Read();
             }
             if (outsideTheTags) // if we are outside the tags we print the text
             {
                 Console.Write((char)currentChar);
                 currentChar = reader.Read();
             }
             else
             {
                 currentChar = reader.Read();
             }
         }
     }
 }
开发者ID:novocob,项目名称:TelerikAcademy,代码行数:31,代码来源:BetweenTags.cs

示例15: Main

    static void Main()
    {
        using (StreamReader reader = new StreamReader("test.xml"))
        {
            int prev = ' ';
            List<string> info = new List<string>();
            StringBuilder temp = new StringBuilder();

            for (int c; (c = reader.Read()) != -1; )
            {
                if (prev == '>' && c != '<')
                {
                    while (c != '<' && c != -1)
                    {
                        if (c == '\n') break;

                        if (c != ' ' && c != '\n' && c != '\r' && c != '\t') temp.Append((char)c);
                        c = reader.Read();
                    }

                    if (temp.Length > 0)
                    {
                        info.Add(temp.ToString());
                        temp.Clear();
                    }
                }
                prev = c;
            }

            foreach (string item in info) Console.WriteLine(item);
        }
    }
开发者ID:Rokata,项目名称:TelerikAcademy,代码行数:32,代码来源:ExtractXML.cs


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