Solved

Some small error in java code

Posted on 2011-09-21
7
208 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

624 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