Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

String trim spaces...

Posted on 2004-10-21
4
Medium Priority
?
224 Views
Last Modified: 2010-03-31
Is there a function that will let me get rid of all spaces in a String. I know trim() only get rid of spaces in front and end. If there is no function what would be the quickest way to get rid of all spaces in a string.

Thanks experts
0
Comment
Question by:apparition
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
4 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12370442
try
  yourString.replaceAll("[ ]", "")
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 12370453
Sorry
   yourString.replaceAll(" ", "")
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12370473
These all work
 ;°)

        System.out.println( "   hello  world   ".replaceAll("[ ]", ""));
        System.out.println( "   hello  world   ".replaceAll("[ ]+", ""));
        System.out.println( "   hello  world   ".replaceAll(" ", ""));
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12370533
Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question