1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

String error

Discussion in 'C#' started by Carlos, Mar 2, 2009.

  1. Carlos

    Carlos New Member

    Hello everyone!

    Please! check this code.

    string word="It is a string";
    while (word != '\0')
    {
    Console.Write(word+"\n");
    i++;
    }

    It give an unexpected error, after printing all the letters.
    Can anyone tell me how to remove this error?
     
  2. shabbir

    shabbir Administrator Staff Member

    In C# string is not character array which you can and should loop through
     
  3. Carlos

    Carlos New Member

    So, how can i break this string into characters without error.
    string word;
    Console.Write(word+"\n");

    Please! Write some code for it.
     
  4. xpi0t0s

    xpi0t0s Mentor

  5. shabbir

    shabbir Administrator Staff Member

    Do you want to break it up into characters or print the entire string?
     
  6. Carlos

    Carlos New Member

    I want to break the string into characters, by using while or For loop, and the loop should stop as the string ends.
    My Code is breaking the string but it give error in the last.

    I can also use the condition word.length() but i want to do it as it is done in C++.
    while (word != '\0')
     
  7. shabbir

    shabbir Administrator Staff Member

    Try the Substring function o the [] operator but do not loop it like in C.

    Loop it using the length variable
     

Share This Page