Solved

Change String by pattern

Posted on 2009-05-04
2
172 Views
Last Modified: 2012-05-06
Hi.
Have a preatty easy question. I need the simplest way to do this:

I have Strings like: 12399, 12500, 12204, 1208, 07
I need them to be like this: "123/ 99", "123/ 00", 122/ 04", "12/ 08", "/ 07"

Please note that the last two is valid.
The pattern is "xxxx/ yy" where yy is mandatory.

Any ideas?
0
Comment
Question by:kristian_gr
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 24296390
Try
s = s.replaceAll("(\\d*)(\\d{2})", "$1/$2");

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24296721
:-)
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

803 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