Manipulate String in JAVA?

Asked

Viewed 92 times

2

  • Which bank?

  • 1

    SQL Server, the application always worked, when only one email was registered in the customer’s database, now invented of for one more and gave problem

  • Sorry about the version?

  • What version of the Bank, @Renanpontes?

  • SQL Server Standard 2005, but I will treat after the same query.

  • Note the best test option maybe it pays to do the way I implemented, maybe not, but first of all test...

Show 1 more comment

3 answers

2


If you go directly to SQL use a function junction, SUBSTRING and CHARINDEX:

SELECT SUBSTRING(email, 1,CHARINDEX(';', email)-1) from emails;

where email is the field that holds electronic addresses separated by comma and emails the table name.

Withdrawn response: Soen - How to split a comma-separated value to Columns


A suitability to pick up emails that have no items separated by ;, ie only an email contained in the field without ;:

select CASE WHEN Charindex(';', email)>0 
   THEN Substring(email, 1,Charindex(';', email)-1) ELSE
   email END
from emails

References:

  • 1

    I believe this response is more appropriate

1

  • Thanks for the help.

1

You can use the Java split function to do this.

String email = "[email protected];[email protected]";
String[] emails = email.split(";"); 
System.out.println(emails[0]);

The split function divides a String into several Strings using the given delimiter and returns the parts in a String vector. Since you only need the first, just use:

emails[0]

See working on ideone.

  • Thanks for the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.