Sunday, March 31, 2013

How do I split a string in Java to extract the user name of the e-mail address?

Main issue made by The Oracle: How do I split a string in Java to extract the username of an email address?

I have a string that is getting an email adress from a previous form and I want to split this email address and disgard everything after and including the @ sign.


I have:

String EMAIL = req.getParameter(“EMAIL”).trim();


and I know I need to do some kind of String.split(‘@’) but I can’t get it to work. Please can someone help me?


Please don’t just paste links to a page that I have probably already googled to myself, or if you think it really is the answer please just cut and paste it in. Also, please don’t be sarcastic or flippant as that really doesn’t help either.


Many thanks.


This can be important facts about How do I split a string in Java to extract the username of an email address? that you’ll must have to clear up dilemmas with their. Ideally this assists in several ways, and then make your own life considerably better. Praying important facts about How do I split a string in Java to extract the username of an email address? may just be a solution to come back.

Solution:


Answer by Sam K

String EMAIL = req.getParameter(“EMAIL”).split(“@”)[0];

will return the string before the at sign.


The trim() function on a String removes the whitespaces before and after the text, so it is not helpful here.


Answer by StormBringer

The split method needs a regular expression. Actually the following should work:


String[] tokens = EMAIL.split(“@”);

String userId = tokens[0];


Otherwise you can always use:


int index = EMAIL.indexof(‘@’);

String userId = null;

if (index!= -1)

{

userId = EMAIL.substring(0,index);

}


Be sure greater?

Add all your answer from a comments!


Subscribe To My Blog: http://www.BruceSolomon.net Get Tools Here: http://brucesolomon.net/marketing-tools/lead-generation-email-marketing-training/ Or Go Dir…


emailing outside the box


Image with emailing outside the box


This hasn’t gone live yet, I still need to tweak the background.


I switched up my usual email design using slices and tables straight out of photoshop.


It didn’t occur to me to use slices until I received an email from PSPrint that used a similar design element to the santa seen here.


Just design with a grid, figure out where you’re going to break the grid and accommodate accordingly.


Since email has to use inline CSS, you have to keep things ridiculously simple. This is all html and tables with a couple of inline styles applied to the body and Table Data’s.


Also inspired by themeforest.net/theme_previews/73915-seasonal-postcard-em…


How do I split a string in Java to extract the user name of the e-mail address?

No comments:

Post a Comment

Blog Archive