read text and found rank(space)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Smurfas
    New Member
    • Jul 2008
    • 30

    read text and found rank(space)

    Code:
    char inputString;
    int i;
    inputString = tr.ReadLine();
    while (inputString != null )
    {
        inputString = tr.ReadLine(); //ascribable text
        if (inputString == ' ') { i++;} //i - how many rank(space)
     }
    What's wrong? Why I get error about char convert to string...
    And why wrong this: (inputString == ' ')

    Thnaks for answer
    Last edited by Curtis Rutland; Jul 17 '08, 05:29 PM. Reason: Added Code Tags - Please use the # button
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Please use code tags, not quote tags when posting. Thanks.

    MODERATOR.

    Now then...

    You haven't shown us the definition of tr but I'll guess that it is a TextReader.

    Your problem is that tr.ReadLine() returns a string. ReadLine() returns a string that contains all the characters up to the end of the line. Even if there is only one character on the line, it will still be a string. You have defined inputString as a char. So, without a cast, that will fail.

    Comment

    Working...