Solved

Some small error in java code

Posted on 2011-09-21
7
203 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now