How to add one more space to a string in Java?

Hi,
I have a string in Java like the following:

myfile.c 1.2.3.4.5

I want to put one more space between c and 1. So it will look like this:

s dir1/dir2/dir3/filename.c 1.1.4.2.2.1 sometext # sometext

The general rules for this case is:

One character Space(s) Some directories filename.c ONESPACECHARACTER somenumbers some space(s) and and some text # sometext

I want to add one more space to ONESPACECHARACTER.

How can I do it?

Thanks,
TolgarAsked:
Who is Participating?
 
CEHJCommented:
This is safer still:


s = s.replaceAll("(\\.[A-Za-z]{1,3}) (\\d)", "$1  $2");

Open in new window

0
 
CEHJCommented:
Try
s = s.replaceAll("(\\.\\w{1,3}) ", "$1  ");

Open in new window

0
 
CEHJCommented:
Or safer maybe
s = s.replaceAll("(\\.[A-Za-z]{1,3}) ", "$1  ");

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
cmalakarCommented:
String s ="myfile.c1.2.3.4.5";
System.out.println(s.replaceFirst("([^.].c)(.*)", "$1 $2"));
0
 
cmalakarCommented:
System.out.println(s.replaceFirst("([^.]\\.c)(.*)", "$1 $2"));
0
 
CEHJCommented:
:)
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.

All Courses

From novice to tech pro — start learning today.