• Post Reply Bookmark Topic Watch Topic
  • New Topic

String replaceAll is not working properly.

 
gemini dev
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have created a simple code where I'd like to remove/ replace more thn 2 white space char with 2 whitespace chars.
this is working fine in my local environment but not at the production server
------------------
private String formatLine(String strLine)
{
if(strLine != null)
{
strLine = strLine.replaceAll(" +", " ");
}
return strLine;
}

------------------
I have checked the Java version and both are running JDK 1.5.

please help,

Thanks,
Vikas
 
Shiva Kumar V
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

strLine = strLine.replace( "+", " " );
Use replace instead of replace all
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gemini dev wrote:Hi All,

I have created a simple code where I'd like to remove/ replace more thn 2 white space char with 2 whitespace chars.
this is working fine in my local environment but not at the production server
------------------
private String formatLine(String strLine)
{
if(strLine != null)
{
strLine = strLine.replaceAll(" +", " ");
}
return strLine;
}

------------------
I have checked the Java version and both are running JDK 1.5.

please help,

Thanks,
Vikas


the previous answer, "use replace" is a little off as String.replace() does not use regular expressions, so it could work if you said
replace (" "," ")

I don't know why your code is working in one place and not the other. What are the results you are seeing?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"gemini dev", please check your private messages for an important administrative matter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!