I have a text box where I enter the input as
"Two; [email protected];"
string[] result = txt_to.Text.Split(';');
so what happens here is the result takes three strings. 1. two 2. [email protected] 3. "" (empty space) since there is a ; after the email it considers that as a string how can I discard the 3rd string that it takes. It happens when I enter the email and a semicolon and press the space bar it throws a error. If it is just space after the semicolon the split should discard it how to do that
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
// Splits str[] according to given delimiters. // and returns next token. It needs to be called // in a loop to get all tokens. It returns NULL // when there are no more tokens.
The string split() method breaks a given string around matches of the given regular expression. After splitting against the given regular expression, this method returns a string array.
The C function strtok() is a string tokenization function that takes two arguments: an initial string to be parsed and a const -qualified character delimiter. It returns a pointer to the first character of a token or to a null pointer if there is no token.
I'm gathering you want to split the string into a number of strings, but exclude any "empty" strings (those consisting only of whitespace)? This ought to help you out...
string[] result = txt_to.Text.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
var arr = mystring.Split(new string[]{";"}, StringSplitOptions.RemoveEmptyEntries);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With