• Post Reply Bookmark Topic Watch Topic
  • New Topic

Split String using delimiter in Java  RSS feed

 
Varshini Priya
Ranch Hand
Posts: 95
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help in splitting two email address which are seperated by a Delimiter 'AND'. I have issue when splitting, when the email address has got the characters'AND' in the email id. For eg, if the email address that needs to be split is something like the below.

'anandc@AND.comANDxyz@yahoo.co.in', and the delimiter is'AND'

There are no whitespaces between the two email address and the delimiter 'AND'.In the above case, there seems to be three items extracted instead of two. Can someone please help me solve this. Thanks in Advance
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not that simple.
Assume the string is
'abb@aaa.comANDbbb.comANDccc@xxd.com'

Are the emails
'abb@aaa.com' & 'bbb.comANDccc@xxd.com'
or
'abb@aaa.comANDbbb.com' & 'ccc@xxd.com'
?

How will you know?
What have you tried?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing I can come up with right now is the first occurrence of AND after the first occurrence of . (dot) should be the delimiter.
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:The only thing I can come up with right now is the first occurrence of AND after the first occurrence of . (dot) should be the delimiter.

Won't work. See my previous post. AND could be a part of a sub-domain or an username that contains a dot.

Generally the choice of delimiter is very poor! Choosing a delimiter that could be also a part of data is very bad idea.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Drat! Didn't think of that one. Back to the drawing board.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seem silly to me to use AND as the delimiter but ...

Since the domain name is normally in lower case (though it is not case sensitive) I would just split on the capitalised "AND" ! Of course this will fail if the address part contains AND but in this case one is stuffed.
 
Varshini Priya
Ranch Hand
Posts: 95
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response all. The emails are like always like this



In the above case, the delimiter is 'AND'. I tried using pattern matcher. But this also dosent seem to work
 
Swastik Dey
Rancher
Posts: 1815
15
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this help?

 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:Does this help?


Does not work if AND is in domain name after a dotor in username after a dot
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably won't like this advice but in your position I would go back to whoever specified it and politely tell them that the use of the word AND as a delimiter is just plain stupid !
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!