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


C# StreamReader.DiscardBufferedData方法代码示例

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


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

示例1: Start

    // Use this for initialization
    void Start()
    {
        possibleLocations = new ArrayList();
        //map to be loaded

        //read out map out of textfile
        StreamReader sr = new StreamReader(Application.dataPath + "\\levels\\" + levelMenu.currentLevel + ".txt");

        int rowcount = 0;
        int columncount = 0;
        string currentline = "";
        while((currentline = sr.ReadLine()) != null)
        {
            if(rowcount == 0)
            {
                foreach(char c in currentline)
                    columncount++;
            }
            rowcount++;
        }

        currentmap = new int[columncount,rowcount];

        sr.BaseStream.Position = 0;
        sr.DiscardBufferedData();

        for (int i = 0;i < rowcount;i++)
        {
            currentline = sr.ReadLine();
            #region Read properties
            if(currentline.Contains("#")){
                if(currentline.Contains("jumppads")){
                    MatchCollection match = Regex.Matches(currentline.Substring(9), "[0-9]+[,][0-9]+");
                    foreach (Match c in match){
                        //long coordinate check
                        int coordinateLength = this.ParseLength(c.Value);
                        //+1 for comma
                        Vector2 co = new Vector2(float.Parse(c.Value.Substring(0,coordinateLength)), float.Parse(c.Value.Substring(coordinateLength+1)));
                        Instantiate(Resources.Load("jumppad"),new Vector3(co.x,-4.5f,co.y),Quaternion.identity * Quaternion.Euler(new Vector3(-90,0,0)));
                        //TODO: Jump via coordinates or collision??
                    }
                }
                else if (currentline.Contains("iceblocks"))
                {
                    MatchCollection match = Regex.Matches(currentline.Substring(10), "[0-9]+[,][0-9]+");
                    foreach (Match c in match){
                        //long coordinate check
                        int coordinateLength = this.ParseLength(c.Value);
                        //+1 for comma
                        Vector2 co = new Vector2(float.Parse(c.Value.Substring(0,coordinateLength)), float.Parse(c.Value.Substring(coordinateLength+1)));
                        Instantiate(Resources.Load("iceblock"),new Vector3(co.x,-4.5f,co.y),Quaternion.identity * Quaternion.Euler(new Vector3(-90,0,0)));
                    }
                }
            }
            else{
            #endregion

                for (int j = 0;j < columncount; j++)
                {
                    currentmap[j,i] = int.Parse(currentline[j].ToString());

                }
            }
        }

        sr.Close();
        //readout end

        //loop through all iceblocks to displace blocks with tiles, put more blocks above and remove normal blocks that collide
        foreach(GameObject iceObject in GameObject.FindGameObjectsWithTag("ice"))
        {
            //not done yet
        }

        // loop through the arrays and spawn a tile whenever there is a 1 and spawn blocks if theres a higher number
        for (int i = 0;i < currentmap.GetLength(0);i++ )
            {
                for (int j = 0; j < currentmap.GetLength(1); j++)
                {
                    if(currentmap[i,j] == 0)
                    {

                    }
                    else if (currentmap[i,j] == 1)
                    {
                        Instantiate(Resources.Load("tile"),new Vector3(i,-5,j),Quaternion.identity);

                        possibleLocations.Add(new Vector3(i,-5,j));
                    }
                    else
                    {
                        float yPosition = -6f + currentmap[i,j];
                        bool upperSpawn = true;
                        while (yPosition > -5f)
                        {
                            Instantiate(Resources.Load("block"),new Vector3(i,yPosition,j),Quaternion.identity);

                            if(upperSpawn)
                            {
//.........这里部分代码省略.........
开发者ID:JanWerder,项目名称:Acedia,代码行数:101,代码来源:levelMode.cs

示例2: DoConvert


//.........这里部分代码省略.........
                        }
                    }

                    dataCount = lineSplitted.Length;
                    comments = false;
                    lines++;
                }
            }

            bool skipRow = false;
            int skippedRows = 0;

            if (!double.TryParse(lineSplitted[0], out x)) skipRow = true;
            if (!double.TryParse(lineSplitted[1], out y)) skipRow = true;
            if (!double.TryParse(lineSplitted[2], out z)) skipRow = true;

            if (skipRow)
            {
                skippedRows++;
                Debug.LogWarning("First point data row was skipped, conversion will most likely fail (rawline:" + rawLine + ")");
            }

            if (enableManualOffset || autoOffsetNearZero)
            {
                manualOffset = _flipYZ ? new Vector3((float)x, (float)z, (float)y) : new Vector3((float)x, (float)y, (float)z);
            }

            if (_useUnitScale) manualOffset *= _unitScale;

            EditorUtility.ClearProgressBar();

            lines = masterPointCount;

            reader.DiscardBufferedData();
            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            reader.BaseStream.Position = 0;

            if (commentLines > 0)
            {
                for (int i = 0; i < commentLines; i++)
                {
                    reader.ReadLine();
                }
            }

            pointArray = new PointData[masterPointCount];

            long rowCount = 0;
            double tempVal = 0;

            for (rowCount = 0; rowCount < masterPointCount - 1; rowCount++)
            {
                if (rowCount % 64000 == 1)
                {
                    EditorUtility.DisplayProgressBar(_appName, "Processing points..", rowCount / (float)lines);
                }

                rawLine = reader.ReadLine().Trim();
                rawLine = rawLine.Replace(",", "."); // for cgo/catia asc
                rawLine = Regex.Replace(rawLine, "[^.0-9 ]+[^e\\-\\d]", "").Trim(); // cleanup non numeric
                rawLine = rawLine.Replace("   ", " ").Replace("  ", " ").Trim();
                lineSplitted = rawLine.Split(' ');

                if (lineSplitted.Length == dataCount)
                {
                    if (!double.TryParse(lineSplitted[0], out x)) skipRow = true;
开发者ID:ruben-farrus,项目名称:the-airport-prototype,代码行数:67,代码来源:MeshConverter.cs

示例3: Main

 static void Main()
 {
     string decorationLine = new string('-', 80);
     Console.Write(decorationLine);
     Console.WriteLine("***Deleting from a text file all words that are listed in another text file***");
     Console.Write(decorationLine);
     // All files are in bin\Debug directory of the project
     string testFile = "Test.txt";
     string wordsFile = "Words.txt";
     Console.WriteLine("The words to be deleted from file '{0}' are in file '{1}'.", testFile, wordsFile);
     try
     {
         StreamReader reader1 = new StreamReader(testFile, Encoding.GetEncoding("UTF-8"));
         StreamReader reader2 = new StreamReader(wordsFile, Encoding.GetEncoding("UTF-8"));
         StringBuilder newContent = new StringBuilder();
         using (reader1)
         {
             using (reader2)
             {
                 char currentChar = new char();
                 string currentTestWord = null;
                 while (!reader1.EndOfStream)
                 {
                     currentChar = (char)reader1.Read();
                     if (char.IsLetterOrDigit(currentChar) || currentChar == '_')
                     {
                         currentTestWord += currentChar;
                     }
                     else
                     {
                         bool removeWord = false;
                         reader2.BaseStream.Position = 0;
                         reader2.DiscardBufferedData();
                         string wordInWordsFile = reader2.ReadLine();
                         while (wordInWordsFile != null)
                         {
                             if (currentTestWord == wordInWordsFile)
                             {
                                 removeWord = true;
                                 break;
                             }
                             wordInWordsFile = reader2.ReadLine();
                         }
                         if (!removeWord)
                         {
                             newContent.Append(currentTestWord);
                         }
                         newContent.Append(currentChar);
                         currentTestWord = null;
                     }
                 }
             }
         }
         StreamWriter writer = new StreamWriter(testFile, false, Encoding.GetEncoding("UTF-8"));
         using (writer)
         {
             writer.Write(newContent);
         }
         Console.WriteLine("Done! You can check the file.");
     }
     catch (DirectoryNotFoundException)
     {
         Console.WriteLine("The specified directory was not found!");
     }
     catch (SecurityException e)
     {
         Console.WriteLine(e.Message);
     }
     catch (UnauthorizedAccessException)
     {
         Console.WriteLine("You don't have the required permission to access the file!");
     }
     catch (FileNotFoundException fileException)
     {
         Console.WriteLine("File '{0}' cannot be found.", fileException.FileName);
     }
     catch (ArgumentException argException)
     {
         Console.WriteLine(argException.Message);
     }
     catch (IOException)
     {
         Console.WriteLine("Fatal error occured!");
     }
 }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:85,代码来源:RemovingWordsFromATextFile.cs


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