Extract words from a string

  • Thread starter Thread starter Maya
  • Start date Start date
M

Maya

Hello guys,

Is there an easy way to extract individual words that form a string and
store them in variables like in this example:

String "how are you?"

My result would be:

var1 = "how"
var2 = "are"
var3 = "you?"

Thanks alot,

Maya.
 
Try this:

string s = "How are you?";

strnig[] tokens = s.Split( ' ' );

string var1 = tokens[0];
strnig var2 = tokens[1];
string var3 = tokens[2];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top