is there a Split function in c#?

im on that thanks , although i am getting an error like this...
Code:
The best overloaded method match for string.Split(params char[]) has some invalid arguments
the way im trying is this...
Code:
			string str = "test 123";
			char buff = Convert.ToChar( " ");
            MessageBox.Show(str.Split(buff,1));
any ideas?
 
The seperator list must be a Char array, not just one Char. I belive
you can just give it a standard string like this:
C#:
String str = "Test 123";

MessageBox.Show(str.Split(" ", 1));
and it will convert the string into a char array. Alternatively, you
can do it like this:
C#:
MessageBox.Show(str.Split(new Char[] {   }), 1));
to use more than one delimeter, you do it like this:
C#:
MessageBox.Show(str.Split(new Char[] {  , |, \n }));
That will split on spaces, pipes, and line-feed characters. Remember
that split can only split using characters, and not whole strings (i.e.
more than one character), so it you try to do that, it will use each
individual character as a delimeter, rather than the whole word.
 
The problem with the first bit of code is too many brackets on the
end. Oops. :p
 
cheers :)
i thought id experiment with an api:-\
Code:
		[DllImport("User32.Dll")]
		public static extern int GetWindowText(int h, StringBuilder s, int nMaxCount);
//// under the forms designer area.
////
		private void button5_Click(object sender, System.EventArgs e)
		{
		    StringBuilder strString = new StringBuilder(256);
			//buffer for the text we want to receive.
            int i;
			i = GetWindowText(this.button1.Handle.ToInt32(),strString,256);
            MessageBox.Show (strString.ToString());
		}
and it works:D
this is cool:p
 
Theres a params overload for Split which means you can pass a comma-delimited list of chars (or just one). As in:
C#:
string s1 = "Hello World This Is Dan";
string[] s2 = s1.Split( );
// or
string[] s3 = s1.Split( , ., ;);

You could also create the array, as in:
C#:
string s1 = "Hello World This Is Dan";
string[] s2 = s1.Split(new char[] { });
// or
string[] s3 = s1.Split(new char[] { , ., ;});

-Ner
 
Back
Top