Skip to main content
gamedev.net
🔒 Locked

[.net] String manipulation

Started by p997 Apr 21, 2006 at 4:39 AM 2 replies 650+ views
Original Post
p997
p997
hi, pls excused me for asking a newbie question, but how do i extract individual char out of a string? For example, i have a string(called field)which contains 13 letters, how do i loop through the string and extract each char inside of it? for (int i = 0; i< 13; i++) { switch (field(i)) <--- Obviously wrong, but what should i put in there? { case "w": .... break; case "e": .... break; . . . default: break; } } Thanks in advance for the helps.
blaze02
blaze02
Strings overload the bracket operator []. Try "field" for the character at position i. Also, the size of the string (13) can also be gotten from field.size().
p997
p997
hehe, thx. how silly of me to use () instead of [] as an array.
Machaira
Machaira
Quote:
Original post by p997
hehe, thx. how silly of me to use () instead of [] as an array.

Not silly, just the wrong language. [grin]
Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.