i know there similar questions regarding this. however, tried many solutions , not work me.
i need extract multiple substrings string:
string content = "ben conan general manager 90010021 benconan@gmail.com";
note: content in string may not in format, may jumbled up.
i want extract phone number , email below:
1. 90010021
2. benconan@gmail.com
in project, trying result , display 2 different edittext. have tried using pattern , matcher class did not work.
i can provide codes here if requested, please me ~
--------------------edit---------------------
below current method take out email address:
private static final string email_pattern = "[a-za-z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + "\\@" + "[a-za-z0-9][a-za-z0-9\\-]{0,64}" + "(" + "\\." + "[a-za-z0-9][a-za-z0-9\\-]{0,25}" + ")+"; public string emailvalidator(string email) { pattern pattern = pattern.compile(email_pattern); matcher matcher = pattern.matcher(email); if (matcher.find()) { return email.substring(matcher.start(), matcher.end()); } else { // todo handle condition when input doesn't have email address } return email; }
you can separate string arraylist this
string str = "ben conan, general manager, 90010021, benconan@gmail.com"; list<string> list = arrays.aslist(str.split(" "));
Comments
Post a Comment