Thomas Thomas - 13 days ago 5
Java Question

string.replaceAll(...) is returning memory address instead of string

I am using the following code to take out the periods (".") in a string:

out.println(tempSentence);
String stripPunctuation = tempSentence.replaceAll(".", "");
out.println(stripPunctuation);


But the console is printing a memory location of the String instead of the string itself. The first line prints out tempSentence successfully, but the third line stripPunctuation prints out a memory address.

Answer

http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)

replaceAll takes in a regular expression. '.' meaning any character except newline. try escaping your '.' with a blackslash (ie: '\\.')

or as gulllie said in the comments, you can also use String.replace(String,String)

Comments