Ratha Ratha - 2 months ago 7
Java Question

String.replaceAll not working for "."

I try to replace all "." with "_".

I tried

string.replaceAll("\\.", "_");


and

string.replaceAll("[.]", "_");


Both are not working. Means "." is not replaced by "_"

Answer

Here ma'am try this one.

var str = '. h .e.l.o. HELLO';
var var1 = str.replace(/\./g, '_');

alert(var1);

FIDDLE