i want to mask the creditcard number which gets displayed in my log files .
i have a class for creditcard processing which gets the information abt creditcard and writes it to a log file - i have to find the position of the cc in the long string" transaction string" which has details abt user id etc too.
this is what i have done so far
int logtranString = transactionString.indexOf("cc");
can anyone please help me in accomplishing the rest of it.
when i use StringBuilder SB= new String Builder(); I am getting an error message that -- string builder not defined. i have imported java.util.*; is there any other class to be imported to use this.
jvm on my machine is 1.5 version.
Steve Luke wrote:This may be a good place to use RegEx with the String.replaceAll(regex, replacement) method.
Look into the Pattern API and see if you can't find a Pattern that would match:
"4 digits" dash "4 digits" dash "4 digits" dash "4 digits" coming after "cc"
If you aren't familiar with RegEx then your strategy may be:
Use a StringBuilder:
Copy all the contents of the String before the indexOf("cc") [perhaps + 2 so "cc" appears in the output] into the StringBuilder
Append the mask for the credit card number onto the StringBiolder
Append all the contents of the String after indexOf("cc") + 2 + length of the credit card number into the StringBuilder