Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Removing spaces from a Java string

Posted on 2007-10-16
2
Medium Priority
?
8,582 Views
Last Modified: 2013-11-23
I have a simple java program reading a name of type string from the database.
If the string contains 2 spaces between the first name and the second name I want to remove one of these spaces. Example if the database contains the name David  Jones (2 spaces between David and Jones) I want to return David Jones(only 1 spaces between David and Jones).

Seems simple but confusing me none the less??
Thanks in advance
0
Comment
Question by:mr_kirbs
2 Comments
 
LVL 92

Accepted Solution

by:
objects earned 150 total points
ID: 20084839
try something like:

s = s.replaceAll("  +", " ");
0
 

Author Comment

by:mr_kirbs
ID: 20085129
What I used:

.replaceAll("  ", " ");

Cheers
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

580 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