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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
JureRank #2,128 · 670 reputationPosted Nov 2, 2010, 6:19 AM EDT
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.
vishnu krishnan103 reputationPosted Nov 2, 2010, 9:57 AM EDT
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
JureRank #2,128 · 670 reputationPosted Nov 2, 2010, 10:08 AM EDT
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 krishnan103 reputationPosted Nov 3, 2010, 7:15 AM EDT
example...
printf("helloworld");
i want to get the helloworld from this statement. using any regular expression?
Suthish NairRank #92 · 22.8K reputationPosted Nov 3, 2010, 8:18 AM EDT
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.