Novice User Novice User - 2 months ago 9
Java Question

Obfuscate a String of date pattern

I have String's for Date pattern like

mm/dd/yyyy
,
mm-dd-yyyy
,
mm.dd.yyyy
etc.

I want to obfuscate it like this
##/##/####
,
##-##-####
,
##.##.####


One idea could be to use
replaceAll
for 'm', 'd', 'y' . But is there any other cleaner solution?

Answer

Many ways to that.

A very simple thing: after you created normally formatted date strings (like 2016-09-08); to take that date and replace any digit with #.

Of course, that has one big advantage: you do a lot of processing; just to throw all of the computed output away in the end.

So, you better rework your formats, like:

obscuredFormat = regularFormat.replaceAll("[mMdy]", "#");
Comments