Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

i'm on that thanks , although i am getting an error like this...

The best overloaded method match for 'string.Split(params char[])' has some invalid arguments

the way i'm trying is this...

		string str = "test 123";
		char buff = Convert.ToChar( " ");
           MessageBox.Show(str.Split(buff,1));

any ideas?

  • *Experts*
Posted

The seperator list must be a Char array, not just one Char. I belive

you can just give it a standard string like this:

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:

MessageBox.Show(str.Split(new Char[] { ' ' }), 1));

to use more than one delimeter, you do it like this:

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.

  • Leaders
Posted

cheers :)

i thought i'd experiment with an api:-\

	[DllImport("User32.Dll")]
	public static extern int GetWindowText(int h, StringBuilder s, int nMaxCount);
//// under the form's 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

  • *Experts*
Posted

There's a params overload for Split which means you can pass a comma-delimited list of chars (or just one). As in:

string s1 = "Hello World This Is Dan";
string[] s2 = s1.Split(' ');
// or
string[] s3 = s1.Split(' ', '.', ';');

 

You could also create the array, as in:

string s1 = "Hello World This Is Dan";
string[] s2 = s1.Split(new char[] {' '});
// or
string[] s3 = s1.Split(new char[] {' ', '.', ';'});

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...