Solved

Some small error in java code

Posted on 2011-09-21
7
206 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reverse digits of a number using for loop 5 52
login jsp example 24 69
jmss example java 2 24
Why doesn't this text field show up on my Applet frame? 2 20
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

820 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