Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
string mytext = textBox1.Text;
string[] parts = mytext.Split(mytext,"@");
textBox2.Text = parts[1];


and my error


Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
Error 2 Argument '1': cannot convert from 'string' to 'char'
Error 3 Argument '2': cannot convert from 'string' to 'char'
Posted
Comments
Sergey Alexandrovich Kryukov 22-Feb-12 12:05pm    
Oh, I can see who we are dealing with... not a though that something can be wrong with you, right?
--SA

try this,
C#
string[] parts = mytext.Split(new char[]{'@'});

More Info[^]

Hope it helps :)
 
Share this answer
 
v2
Comments
newbie011292 21-Feb-12 21:42pm    
still i got it wrong, but anyway thanks for the help sir
An array of strings compiles.
tn.Split(new string[]{"one","two"}, 2, StringSplitOptions.RemoveEmptyEntries);
 
Share this answer
 
Comments
newbie011292 21-Feb-12 21:43pm    
sorry sir but i dont understand, anyways thanks 4 the help sir
you can do as below. i have replace double quote to single quote because split function is not support string as a parameters, either we have to pass char or char array. if we write double quote, it become a string

C#
string[] parts = mytext.Split('@');
 
Share this answer
 
Hi,

First of all I would like to know the textBox1.Text.
Does above has text contains "@" character?

Second is that how many "@" in textBox1.Text?

Executing these code:
C#
string mytext = textBox1.Text;
string[] parts = mytext.Split(mytext,"@");
textBox2.Text = parts[1];



Scenario 1
mytext contains 1 "@" character.

C#
textBox2.Text = parts[1];  // Error  invalid arguments

Because index start at 0

Try to execute:
C#
textBox2.Text = parts[0];  // No error valid arguments


Array index start at 0.


Please vote if could help...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900