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


C# StreamReader.Peek方法代码示例

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


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

示例1: Main

    static void Main()
    {
        // TODO: Skip whitespace
        using (StreamReader input = new StreamReader("../../input.txt"))
            for (int i; (i = input.Read()) != -1;) // Read char by char
                if (i == '>' && input.Peek() != '<' && input.Peek() != '\r' && input.Peek() != '\n')
                    while ((i = input.Read()) != '<') // Inside text node
                        Console.Write((char)i);

        Console.WriteLine();
    }
开发者ID:tod44,项目名称:TelerikAcademy,代码行数:11,代码来源:Program.cs

示例2: loadData

    public void loadData()
    {
        StreamReader sr;

        sr = new StreamReader (pathT + "/test.txt");
        //		string[] txt = {"aho","aho"};

        print (sr.Peek ());

        while(sr.Peek()>-1){
            print (sr.ReadLine());
        }
    }
开发者ID:tetsuyamaguchi,项目名称:BOXStetsu,代码行数:13,代码来源:loadTextTest.cs

示例3: ControlFile

 // カメラなどの座標が書き込まれた行を力技で強引に編集
 void ControlFile(int n)
 {
     string tmpFile = Path.GetTempFileName();
     using (StreamReader sr = new StreamReader(PATH))
     using (StreamWriter sw = new StreamWriter(tmpFile))
     {
         int ReferLine = 0;  // 参照する行
         while (sr.Peek() > -1)
         {
             string line = sr.ReadLine();    // 読み込んだ一行
             ++ReferLine;
             if (1 == ReferLine)
             {
                 sw.Write(n);
             }
             else if (n + 3 == ReferLine)
             {
                 sw.Dispose();
             }
             else
             {
                 sw.Write("\n" + line);
             }
             //ReferLine++;
         }
         //閉じる
         sr.Close();
         sw.Close();
     }
     //入れ替え
     File.Copy(tmpFile, PATH, true);
     File.Delete(tmpFile);
 }
开发者ID:backspace229,项目名称:NUIMolecularModel,代码行数:34,代码来源:PrintPosition.cs

示例4: Get_Http

    //获取远程服务器ATN结果
    private String Get_Http(String a_strUrl, int timeout)
    {
        string strResult;
        try
        {
            HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(a_strUrl);
            myReq.Timeout = timeout;
            HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
            Stream myStream = HttpWResp.GetResponseStream();
            StreamReader sr = new StreamReader(myStream, Encoding.Default);
            StringBuilder strBuilder = new StringBuilder();
            while (-1 != sr.Peek())
            {
                strBuilder.Append(sr.ReadLine());
            }

            strResult = strBuilder.ToString();
        }
        catch (Exception exp)
        {

            strResult = "错误:" + exp.Message;
        }

        return strResult;
    }
开发者ID:ichari,项目名称:ichari,代码行数:27,代码来源:Receive.aspx.cs

示例5: CountWords

    //Write a program that reads a list of words from a file words.txt and finds how many times 
    //each of the words is contained in another file test.txt. The result should be written in 
    //the file result.txt and the words should be sorted by the number of their occurrences in 
    //descending order. Handle all possible exceptions in your methods.

    private static Dictionary<string, int> CountWords(string inputPath, string listOfWordsPath)
    {
        List<string> list = ExtractList(listOfWordsPath);
        StreamReader reader = new StreamReader(inputPath);
        Dictionary<string, int> result = new Dictionary<string, int>();

        using (reader)
        {
            while (reader.Peek() != -1)
            {
                string currline = reader.ReadLine();

                for (int i = 0; i < list.Count; i++)
                {
                    Regex word = new Regex("\\b" + list[i] + "\\b");

                    foreach (Match match in word.Matches(currline))
                    {
                        //for each word met, if already met - increase counter, else - start counting it
                        if (result.ContainsKey(list[i]))
                        {
                            result[list[i]]++;
                        }
                        else
                        {
                            result.Add(list[i], 1);
                        }
                    }
                }
            }
        }
        return result;
    }
开发者ID:Varbanov,项目名称:TelerikAcademy,代码行数:38,代码来源:CountSomeWordsInFile.cs

示例6: Main

    public static void Main()
    {
        Stopwatch sw=new Stopwatch();
        sw.Start();
        StreamReader sr = new StreamReader(@"words.txt");
        int count=0;

        fillTriangles();
        foreach(var triangle in  triangles)
        Console.WriteLine("Triangle Number.....{0}",triangle);

        string wordtext="";

        while(sr.Peek()>-1)
        {
           wordtext=sr.ReadLine();
        }
        words=wordtext.Replace("\"","").Split(',');
        foreach(var word in words)
        {
        int temp=0;
        temp=wordScore(word);//get Value
        if (triangles.IndexOf(temp)!=-1)
        count++;
        }
        sw.Stop();
        Console.WriteLine("There were {0} triangle words",count);
        Console.WriteLine("Elapsed time {0} ms",sw.ElapsedMilliseconds);
    }
开发者ID:jmignosa,项目名称:EulerProject,代码行数:29,代码来源:42.cs

示例7: GetJSON

        string GetJSON(string url, string postData, string method) {
            string returnValue = string.Empty;
            WebRequest webRequest = WebRequest.Create(url);
            webRequest.ContentType = "application/x-www-form-urlencoded";

            if (!string.IsNullOrEmpty(method)) {
                webRequest.Method = method;

                if (!string.IsNullOrEmpty(postData)) {
                    // posting data to a url
                    byte[] byteSend = Encoding.ASCII.GetBytes(postData);
                    webRequest.ContentLength = byteSend.Length;

                    using (Stream streamOut = webRequest.GetRequestStream())
                        streamOut.Write(byteSend, 0, byteSend.Length);
                }
            } else
                webRequest.Method = "GET";

            WebResponse webResponse = webRequest.GetResponse();
            using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))
                if (streamReader.Peek() > -1) returnValue = streamReader.ReadToEnd();

            return returnValue;
        }
开发者ID:jonezy,项目名称:Epilogger,代码行数:25,代码来源:FoursquareVenueClient.cs

示例8: Awake

    // Use this for initialization
    void Awake()
    {
        dia = new List<DialogStruct>();
        if (Application.isEditor==true)
        {
            file_path = "Assets/Resources/Dialogs/" + file_name + ".txt";
        }
        else
        {
            file_path =Application.dataPath+"/"+file_name+".txt";
        }
        st_r = new StreamReader(file_path);

        while(st_r.Peek()>-1)
        {
            DialogStruct ds=new DialogStruct();
            tempStr =st_r.ReadLine();
            tempStr.Trim();
            if (tempStr.Contains(":"))
            {
                string[] sp=tempStr.Split(':');
                ds.name = sp[0].Trim();
                ds.dialog = sp[1].Trim();
            }
            else
            {
                ds.name = "";
                ds.dialog = tempStr;
            }
            dia.Add(ds);
        }
        st_r.Close();
    }
开发者ID:cushionbadak,项目名称:Git_Unity_Aura,代码行数:34,代码来源:ParseScripts.cs

示例9: LoadPath

 internal static Path LoadPath()
 {
     Path loadPath = new Path();
     try
     {
         using (StreamReader reader = new StreamReader(@"../../savedPaths.txt"))
         {
             while (reader.Peek() >= 0)
             {
                 String line = reader.ReadLine();
                 String[] splittedLine = line.Split(new char[] { '(', ',', ')' }, StringSplitOptions.RemoveEmptyEntries);
                 loadPath.AddPoint(new Point3D(int.Parse(splittedLine[0]), int.Parse(splittedLine[1]), int.Parse(splittedLine[2])));
             }
         }
     }
     catch (FileNotFoundException)
     {
         Console.WriteLine("File not found, try adding a new file");
     }
     catch (IOException io)
     {
         Console.WriteLine(io.Message);
     }
     catch (OutOfMemoryException ome)
     {
         Console.WriteLine(ome.Message);
     }
     finally { }
     return loadPath;
 }
开发者ID:Nikolay-D,项目名称:TelerikSchoolAcademy,代码行数:30,代码来源:PathStorage.cs

示例10: ExtractTextFromXML

    //Write a program that extracts from given XML file all the text without the tags. 
    //Input: input.txt with valid xml text from the example
    //Output: Pesho, 21, Games, C#, Java

    static string ExtractTextFromXML(string path)
    {
        StringBuilder res = new StringBuilder();
        StreamReader reader = new StreamReader(path);

        using (reader)
        {
            while (reader.Peek() != -1)
            {
                string currLine = reader.ReadLine();
                int openIndex = currLine.IndexOf('>');
                
                //what I do next: find indexes of '>' and of '<', if present, and extract the substring in between
                while (openIndex != -1)
                {
                    int closeIndex = currLine.IndexOf('<', openIndex);
                    if (closeIndex != -1)
                    {
                        string token = currLine.Substring(openIndex + 1, closeIndex - openIndex - 1);
                        res.Append(token);
                        res.Append(", ");
                    }
                    openIndex = currLine.IndexOf('>', openIndex + 1);
                }
            }
        }
        return res.ToString();
    }
开发者ID:Varbanov,项目名称:TelerikAcademy,代码行数:32,代码来源:ExtractOnlyTextFromXML.cs

示例11: GetAllFilesByType

            // Regresa un ArrayList de arreglos de dos cadenas, la primera es el
            // estilo y la segunda es el path al archivo
            public static ArrayList GetAllFilesByType(int type)
            {
                string line, style, path, testPath, stylePath, source;
                ArrayList docs = new ArrayList ();

                testPath = PathOfTest ();
                source = Path.Combine (testPath, "unit-test.sources");

                FileStream mainReader = new FileStream (source, FileMode.Open);
                StreamReader smainReader = new StreamReader (mainReader);

                while (smainReader.Peek () > -1) {
                style = smainReader.ReadLine ();
                stylePath = Path.Combine (testPath, style);
                source = Path.Combine (stylePath, style + ".sources");

                FileStream sourceReader = new FileStream (source, FileMode.Open);
                StreamReader styleReader = new StreamReader (sourceReader);

                while (styleReader.Peek () > -1) {
                string[] array = new string [2];
                line = styleReader.ReadLine ();

                path = Path.Combine (stylePath, Test.GetFileNameByType (line, type));
                array [0] = style;
                array [1] = path;
                docs.Add (array);
                }
                styleReader.Close ();
                }
                smainReader.Close ();

                return docs;
            }
开发者ID:simas76,项目名称:scielo-dev,代码行数:36,代码来源:Test.cs

示例12: getDisabledTests

            public ArrayList getDisabledTests( string location )
            {
                ArrayList testList = new ArrayList( );

                StreamReader sr = new StreamReader( location );

                string[] currentLine;
                DisabledTest disabledTest;

                // add all the test IDs to the list...
                while ( sr.Peek( ) >= 0 )
                {
                    currentLine = sr.ReadLine( ).Split( ( new char[] { ' ', '\t' } ), 2  );

                    disabledTest = new DisabledTest( );

                    if ( currentLine.Length > 0 )
                        disabledTest.testID = currentLine[0];

                    if ( currentLine.Length > 1 )
                        disabledTest.reason = currentLine[1];

                    testList.Add( disabledTest );
                }

                // close the file...
                sr.Close( );

                return testList;
            }
开发者ID:uvbs,项目名称:Holodeck,代码行数:30,代码来源:RunTest.cs

示例13: loadAllExtensionFiles

 private static void loadAllExtensionFiles()
 {
     if (extensionFiles == null)
     {
         string[] filePaths;
         extensionFiles = new Dictionary<String, String>();
         try
         {
             filePaths = Directory.GetFiles("Resources/Extensions/", "*.cs");
         }
         catch (DirectoryNotFoundException)
         {
             return;
         } 
         foreach (String fileName in filePaths)
         {
             TextReader tr = new StreamReader(fileName);
             String result = "";
             while (tr.Peek() >= 0)
             {
                 result += tr.ReadLine() + "\n";
             }
             extensionFiles.Add(fileName, result);
             tr.Close();
         }
     }
 }
开发者ID:skicean,项目名称:ZhongHuaSanGuoZhi,代码行数:27,代码来源:ExtensionInterface.cs

示例14: RemoveWords

    //12.Write a program that removes from a text file all words listed in given another text file. Handle all possible exceptions in your methods.

    static void RemoveWords(string inputPath, string listedWordsPath)
    {
        List<string> list = ExtractList(listedWordsPath);
        List<string> outputLines = new List<string>();
        StreamReader reader = new StreamReader(inputPath);
        using (reader)
        {
            while (reader.Peek() != -1)
            {
                string currLine = reader.ReadLine();

                for (int i = 0; i < list.Count; i++)
                {
                    //match each word from the list in the current line and replace it with empty string if matched
                    string currWord = "\\b" + list[i] + "\\b";
                    currLine = Regex.Replace(currLine, currWord, "");
                }
                outputLines.Add(currLine);
            }
        }
        //overwrite the file
        StreamWriter writer = new StreamWriter(inputPath);
        using (writer)
        {
            foreach (var line in outputLines)
            {
                writer.WriteLine(line);
            }
        }
    }
开发者ID:Varbanov,项目名称:TelerikAcademy,代码行数:32,代码来源:RemoveListedWords.cs

示例15: Start

    // Use this for initialization
    void Start()
    {
        FileStream fs = new FileStream ("test.dem",FileMode.Create, FileAccess.Write);
        BinaryWriter bw = new BinaryWriter (fs);
        StreamReader sr = new StreamReader ("36814.xyz");
        ArrayList height = new ArrayList ();

        int[] regionMin = new int[2];
        int[] regionMax = new int[2];

        string[] words = (sr.ReadLine()).Split (' ');
        float interval = 90;
        Int32 X = (int)Convert.ToDouble (words [0]);
        Int32 Y = (int)Convert.ToDouble (words [1]);
        height.Add (words [2]);

        regionMax [0] = regionMin [0] = X;
        regionMax [1] = regionMin [1] = Y;

        while (sr.Peek() >= 0) {
            words = (sr.ReadLine()).Split (' ');
            X = (int)Convert.ToDouble (words [0]);
            Y = (int)Convert.ToDouble (words [1]);
            height.Add (words [2]);

            if(regionMax[0]<X)
                regionMax[0] = X;
            if(regionMin[0]>X)
                regionMin[0] = X;

            if(regionMax[1] <Y)
                regionMax[1] = Y;
            if(regionMin[1] > Y)
                regionMin[1] = Y;

        }

        bw.Write (interval);
        bw.Write (regionMin [0]);
        bw.Write (regionMin [1]);
        bw.Write (regionMax [0]);
        bw.Write (regionMax[1]);

        for (int i=0; i<height.Count; i++) {
            bw.Write(Convert.ToDouble(height[i]));
        }

        //bw.Write (Convert.ToDouble(words[0]));
        //bw.Write (Convert.ToDouble(words[1]));

        /*FileStream fs2 = new FileStream ("test.dem", FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader (fs2);
            Console.WriteLine (br.ReadDouble());
            Console.WriteLine (br.ReadDouble());*/

        sr.Close ();
        bw.Close ();
        fs.Close ();
    }
开发者ID:Hyunsik-Yoo,项目名称:Flood-Simulation,代码行数:60,代码来源:DEMTransfer.cs


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