how to read each character from a string using c sharp
how can i take each character from a string or a word using c sharp?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Nov 3, 2010, 12:18 PM
Your post question now changed from the original.
Please, Accept Jure post as answer for your original post if solved.
Then create or ask as a new question about regular expression.
Note: This not the matter of answering your post, i can provide the answer also.
Because each forum post can have only one accepted answer.
vishnu krishnanPosted Nov 3, 2010, 11:15 AM
example...
printf("helloworld");
i want to get the helloworld from this statement. using any regular expression?
JurePosted Nov 2, 2010, 2:08 PM
foreach (char ch in sample)
{
Console.WriteLine(ch);
}
// or, if you need more control:
for (int c = 0; c < sample.Length; ++c)
{
Console.WriteLine(sample[c]);
}
vishnu krishnanPosted Nov 2, 2010, 1:57 PM
string sample = "abc123 and a few othEr words with spaces in-between";
Console.Write(sample[20]); // outputs 'E'
here i have to specify the position ya ([20]), but i need
example: "word"; this a string
i have to get the output like
output: w
o
r
d
waiting for ur reply
JurePosted Nov 2, 2010, 10:19 AM
string sample = "abc123 and a few othEr words with spaces in-between";
Console.Write(sample[20]); // outputs 'E'
However, you cannot set a character the same way, you'll have to use string.Remove and string.Insert. It's as if string class had an indexer of type char, that has only get block implemented.