aspose file tools
The moose likes Beginning Java and the fly likes java string[] splitting for email id Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "java string[] splitting for email id" Watch "java string[] splitting for email id" New topic
Author

java string[] splitting for email id

Mobio Dev
Greenhorn

Joined: Nov 03, 2010
Posts: 6
hi experts, I'm having String temp = "Ms Abc<abc@gmail.com>;Mr Cde<cde@mail.com>;Miss Xyz<xyz@mail.com>";

now i have to split this temp string to ArrayList or String[] title, name, emailid so i'm able insert into db separate column for title, name and emailId, i'm able only split the email id using following code,

ArrayList emailIdList = new ArrayList();
Pattern p = Pattern.compile("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b",Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(s);
while (m.find()){
emailIdList.add(m.group());
}
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16815
    
  19

Mobio Dev wrote:
now i have to split this temp string to ArrayList or String[] title, name, emailid so i'm able insert into db separate column for title, name and emailId, i'm able only split the email id using following code,


Well, you pretty much got the hardest one done. Just put the email pattern in a group, and then add the groups for the title and name. Compare to the email, the other two groups should be easy.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
And welcome to JavaRanch
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: java string[] splitting for email id
 
Similar Threads
Hibernate Stale State Exception
org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8
findby method returning multiple records..
Custom validation ignored
Updating duplicate rows