Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   String error (http://www.go4expert.com/forums/string-error-t16400/)

Carlos 3Mar2009 02:14

String error
Hello everyone!

Please! check this code.

string word="It is a string";
while (word[i] != '\0')

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

shabbir 3Mar2009 09:06

Re: String error
In C# string is not character array which you can and should loop through

Carlos 3Mar2009 22:53

Re: String error
So, how can i break this string into characters without error.
string word;

Please! Write some code for it.

xpi0t0s 4Mar2009 01:42

Re: String error
Could this be what you're looking for:

shabbir 4Mar2009 09:12

Re: String error
Do you want to break it up into characters or print the entire string?

Carlos 4Mar2009 23:08

Re: String error
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[i] != '\0')

shabbir 4Mar2009 23:17

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

Loop it using the length variable

All times are GMT +5.5. The time now is 01:44.