Re: read text file

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
>
>
>
>
>
>
>
>
>


.



Relevant Pages

  • HTMLEncode: low surrogate char Error
    ... UTF characters that are part of the default windows code page throw an ... you will avoid throwing the exception. ... Dim _textStreamReader As StreamReader ... Function GetResource(ByVal ResourceName As String) ...
    (microsoft.public.dotnet.general)
  • Re: How does this work?
    ... Let's say the string value is ... The value of the first argument is the substring that matched. ... the match extends as long as the delimiter characters don't match. ... So, as you can probably see now, it is actually a simple template engine ...
    (comp.lang.javascript)
  • Re: "Reversed" LCS problem
    ... have to worry so much about defining "substring" versus "subsequence," ... say "the letters in the string must be next to each other, ... >> has the lowest number of common characters from the other strings, ... > No whitespaces, no sequences, only substrings. ...
    (comp.programming)
  • Re: Deleting substrings
    ... substring is present in the string or not. ... We start at the beginning of the string. ... We copy the characters from the point immediately after ... redundant scans of the host string. ...
    (comp.programming)
  • Re: split a string
    ... >I have a string of N characters. ... >more ‘*' characters, which are the delimiter for the substring. ...
    (alt.comp.lang.learn.c-cpp)