Originally posted by Gopu Akraju:
I could remove all the white spaces using simple regex as
Others have pointed out some problems with this, namely
String.replace() isn't a regex method. Use String.replaceAll() for regex replacement." " will replace only spaces, not other whitespace.You probably don't want to get rid of whitespace between words. But those things aside, you still have the original problem.
name.replace(" ", ""); does not modify
name but instantiates a new String object, so you would want something like
name = name.replace(" ", ""); Probably easiest is to just do
name = name.trim() as it doesn't have the above problems.
[ May 08, 2008: Message edited by: Brian Cole ]