Hi,
Split method returns a string array. If the specified separator character is not in the string provided, then it will just return a string array with a single element (0th index). So in a case like that it is not possible to retrieve an element with index equals 1. This is correct if you can guarantee the specified separator character is in the string provided. One of the following can be used to ensure that,
if (mystring.Contains("@"))
{
string result1 = mystring.Split('@')[1];
}
or
var result = mystring.Split('@');
if (result.Length >= 1)
{
string result1 = mystring.Split('@')[1];
}
Also, you don't have to use
string myString = txtEmail.Text.ToString();
as
txtEmail.Text
is string itself.
Regards.