How do you select the nth char of a string?

Fiveohhh

Diamond Member
Jan 18, 2002
3,776
0
0
Just curious about how you would do this.

say you have string "abcdeft"

I want to grab the 4th element('e') and put it into something else.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
You can index strings in C# just like you would an array.

so mystring[3] would return the 4'th character in the string.

edit: After rereading your post.... the 4th element of your string is 'd', not 'e'. 'e' happens to be at index 4, but it is the 5th element in the string.


 

Fiveohhh

Diamond Member
Jan 18, 2002
3,776
0
0
Thanks for the info, I tired searching msdn, but I need to revise my search strings as I didn't get much for results


edit: back button didn't work so well there
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Originally posted by: Fiveohhh
Thanks for the info, I tired searching msdn, but I need to revise my search strings as I didn't get much for results


edit: back button didn't work so well there

Usually I search for the type of the object that I'm looking to manipulate and browse from there to find what I need. MSDN is usually pretty good about providing links between various pages of related information.