• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String replaceAll is not working properly.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

strLine = strLine.replace( "+", " " );
Use replace instead of replace all
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"gemini dev", please check your private messages for an important administrative matter.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic