954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

what is the easiest way to get words in a string?

i am creating a small cpu simulator and i need to parse the assembly instruction which is like "add $s1 $s2 $s3", i need to get these four individual words ignoring the white spaces, if i use string.split(' '), it wont work if user enters more than one space between the words. i think of implementing it using subscript, but there should be easier way.
any ideas?

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

Try str.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); .

nmaillet
Posting Whiz in Training
236 posts since Aug 2008
Reputation Points: 69
Solved Threads: 53
 
Try str.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries); .


if that works i will kiss you on your forehead.

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

wow it worked :

string something = "ali veli      deli";
        string[] somethings = something.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);

        Response.Write(somethings.Length.ToString());

the output is 3 as expectedly.
now the question for you, how were you able to find this information?

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

I found it in the class library reference at the MSDN. http://msdn.microsoft.com/en-us/library/ms229335.aspx

nmaillet
Posting Whiz in Training
236 posts since Aug 2008
Reputation Points: 69
Solved Threads: 53
 

do you also know how to deselect all rows in a windows application?

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

i found it :

foreach (DataGridViewRow dr in DataGridName.SelectedRows)
{
  dr.Selected = false;
}
serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You