Re: read text file
- From: "microsoft.news.com" <CSharpCoder>
- Date: Tue, 24 May 2005 15:56:07 -0400
its breaking on the very first line in the text file do to the line is only
20 characters long and I need to look for the item at position 31.
I get the following error "input string is in the incorrect format" and this
is do to nothing being there.
"Bill Butler" <Bi@xxxxxxxxxxxxxxx> wrote in message
news:eolF0SJYFHA.2076@xxxxxxxxxxxxxxxxxxxxxxx
> "microsoft.news.com" <CSharpCoder> wrote in message
> news:utgsaNIYFHA.3584@xxxxxxxxxxxxxxxxxxxxxxx
>> here is what i have
>>
>> StreamReader sr = new StreamReader("file.txt")
>> {
>> string line = sr.ReadLine();
>> while ((line = sr.ReadLine()) !=null)
>> {
>> //needs to start reading from line 2 not line 1
>> string name = line.SubString(31,10);
>>
>> }
>> sr.Close();
>> }
>>
>> I need to use SubString because I need to get only certain dataitems,
>> from the line, not all only 3.
>>
>>
> <OBSERVATION>
> Obviously this is not your actual code since SubString is not a method of
> string (Substring is)
> </OBSERVATION>
>
> First things first:
> What exception are you getting?
> What Line is throwing the exception?
> How Long is that line?
>
> I suspect that you have some line (after the first) that is shorter than
> 41 characters in length.
> You will get something that looks like this:
> System.ArgumentOutOfRangeException: Index and length must refer to a
> location within the string
>
> Try replacing
>
> string name = line.SubString(31,10);
> with
> if (line.Length < 41)
> Console.WriteLine("SHORT:{0}",line);
>
> This should point you to the offending line.
>
> Good luck
> Bill
>
>
>
>
>
>
>
>
>
.
- Follow-Ups:
- Re: read text file
- From: Mythran
- Re: read text file
- From: Jon Skeet [C# MVP]
- Re: read text file
- References:
- read text file
- From: microsoft.news.com
- Re: read text file
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: read text file
- From: Mythran
- Re: read text file
- From: microsoft.news.com
- Re: read text file
- From: Jon Skeet [C# MVP]
- Re: read text file
- From: microsoft.news.com
- Re: read text file
- From: Bill Butler
- read text file
- Prev by Date: UserControls
- Next by Date: Re: read text file
- Previous by thread: Re: read text file
- Next by thread: Re: read text file
- Index(es):
Relevant Pages
|