When my string is mail&mail@mail.com
, the code returns -1.
How can I solve that?
email = mail&mail@mail.com
int arroba = email.IndexOf("@");
I also tried this:
int arroba = email.IndexOf("@", email.IndexOf("&"));
Any help serves me thanks
The problem is that the char you search has different culture from the one in your email string.
Try this:
email = "email = mail&mail@mail.com";
int result = -1;
int and = CultureInfo.InvariantCulture.CompareInfo.IndexOf(email, "&");
if(and!=-1)
result = CultureInfo.InvariantCulture.CompareInfo.IndexOf(email, "@");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.