• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8591
  • Last Modified:

Removing spaces from a Java string

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
mr_kirbs
Asked:
mr_kirbs
1 Solution
 
objectsCommented:
try something like:

s = s.replaceAll("  +", " ");
0
 
mr_kirbsAuthor Commented:
What I used:

.replaceAll("  ", " ");

Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now