开发者

Index out of bounds array exception +Streamreader

开发者 https://www.devze.com 2023-04-07 22:54 出处:网络
I have encountered an array index out of bounds exception based on t开发者_StackOverflow社区he following codes:

I have encountered an array index out of bounds exception based on t开发者_StackOverflow社区he following codes:

I understand that readtoend method may disrupt the pointer for the streamreader, hence i implement the discardbuffereddata and seekorigin 0. However, im still getting an index out of bounds. help please? thanks!

StreamReader sr = new StreamReader(@".\Input\" + inServer + ".txt");
        readall = sr.ReadToEnd();
        string[] splited = Regex.Split(readall, "~~~~~~~~~~~~~~");
        sr.BaseStream.Seek(0, SeekOrigin.Begin);
        sr.DiscardBufferedData();


    while (sr.Peek() >= 0)
            {
                currLine = sr.ReadLine();
}


try modifying your codes as follows:

        readAll = sr.ReadToEnd();
        sr.Close();
        foreach (string s in readAll.Split(new char[] { '\r', 'n' }))
        {

            currLine = s;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号