Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Some small error in java code

Posted on 2011-09-21
7
Medium Priority
?
209 Views
Last Modified: 2012-05-12
if (idType.equals(BusinessCodes.ID_TYPE_SSN))
            {
      
      formattedIdentifier = formatSSN(id);

the formatSSN(id) method will return SSN of form   123-45-6789

now formattedIdentifier = 123-45-6789

I need to plug a code here that will return this formatted identifier as ***-**-6789

I tried following but its not working , I am getting an error "Exception thrown by getter for property formattedIdentifier of bean item"


if (idType.equals(BusinessCodes.ID_TYPE_SSN))
            {
      
      formattedIdentifier = formatSSN(id);

//I am trying the following code

String expression = "^\\d{3}[-]?\\d{2}[-]?\\d{4}$";
CharSequence input = formattedIdentifier;
                  Pattern patt = Pattern.compile(expression);
                  Matcher m = patt.matcher(input);
                  m.replaceAll("***-**-$");
                  formattedIdentifier=(String)input;

}

return formattedIdentifier ;
}
0
Comment
Question by:questjava
[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
  • 5
  • 2
7 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36575223


String output = "***-**-" + formattedIdentifier.substring(7);

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36575241
                 String formattedIdentifier = "123-45-6789";

String output = "***-**-" + formattedIdentifier.substring(7);

        System.out.println(output);

Open in new window


Output:
***-**-6789

Open in new window

0
 

Author Comment

by:questjava
ID: 36575255
I need to return formattedIdentifier to jsp page , I cant go with string output as it will break other things

any suggestion ?
0
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.

 

Author Comment

by:questjava
ID: 36575270
String formattedIdentifier = "12-3456789";

String output = "**-" + formattedIdentifier.substring(3);

        System.out.println(output);
will this work for form  12-3456789 ?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 36575277
It does not matter on jsp page or in application - you can make
a string which you eed and print it in jsp page  

Make it like that and it will print modified string:

formattedIdentifier = "***-**-" + formattedIdentifier.substring(7);
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36575292

This will work in both cases:
formattedIdentifier = "***-**-" + formattedIdentifier.substring(formattedIdentifier.length()-4);
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36575321
This will wortk with all fioms as long as last 4 digits are together

                 String formattedIdentifier = "123-456789";
 //String formattedIdentifier = "12-3456789";

formattedIdentifier = "***-**-" +  formattedIdentifier.substring(formattedIdentifier.length()-4);

        System.out.println(formattedIdentifier);

Open in new window

0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

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…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

670 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