开发者

How to convert encoded email address in Java?

If I receive an emailAddress in the following format:

example%40gmail.com

开发者_StackOverflowIn Java how do I convert it to this:

example@gmail.com


Use URLDecoder.decode(String s, String enc) becuase URLDecoder.decode(String s) is deprecated in Java 1.5.

Here is the code to test your case:

@Test
public void testUrlDecoder() throws UnsupportedEncodingException {
    String encodedStr = "example%40gmail.com";
    String decodedStr = URLDecoder.decode(encodedStr, "UTF-8");
    assertEquals("example@gmail.com", decodedStr);
}


See the answer to this question: Java: How to unescape HTML character entities in Java?


This might be what you want, I haven't had a chance to test it to make sure that what you have is actually a url encoded item:

http://download.oracle.com/javase/1.4.2/docs/api/java/net/URLDecoder.html


This might be a bit simplistic, but you could try:

email = myEmailAddress.getAddress();
email.replace("%40", "@");
myEmailAddress.setAddress(email);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜