simple file i/o help needed

hello... i get the message:

An unhandled exception of type 'System.NullReferenceException' occurred in attempt.exe
Additional information: Object reference not set to an instance of an object.


when executing this:

string blockOne = null;
do
{
blockOne = sr.ReadLine();
Console.WriteLine(blockOne);
}
while ((blockOne.StartsWith(" 2A3:") == (false)));

so im trying just to print all lines of a text file until i get to one starting with " 2A3:". The correct lines are output to the console, but then the execution halts.... i am a real novice!! any help please?

Comments

  • [b][red]This message was edited by baiedronk at 2005-3-17 10:39:34[/red][/b][hr]
    : hello... i get the message:
    :
    : An unhandled exception of type 'System.NullReferenceException' occurred in attempt.exe
    : Additional information: Object reference not set to an instance of an object.
    :
    :
    : when executing this:
    :
    : string blockOne = null;
    : do
    : {
    : blockOne = sr.ReadLine();
    : Console.WriteLine(blockOne);
    : }
    : while ((blockOne.StartsWith(" 2A3:") == (false)));
    :
    : so im trying just to print all lines of a text file until i get to one starting with " 2A3:". The correct lines are output to the console, but then the execution halts.... i am a real novice!! any help please?
    :
    :

    try something like this

    [code]
    while (((blockOne = sr.ReadLine()) != null) && ((blockOne.StartsWith(" 2A3:") == (false))))
    {
    Console.WriteLine(blockOne);
    }
    [/code]


    or maybe even....

    [code]
    while ((blockOne = sr.ReadLine() != null))
    {
    Console.WriteLine(blockOne);
    if (blockOne.StartsWith(" 2A3:")){break;}
    }
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion