Guus2005
AWF VIP
- Local time
- Today, 04:20
- Joined
- Jun 26, 2007
- Messages
- 2,642
This function replaces every character with a random similar character.
I use this function to anonymize data in tables.
Almost but not quite entirely unlike the post made by Micron a few months ago.
Share & Enjoy!
I use this function to anonymize data in tables.
Almost but not quite entirely unlike the post made by Micron a few months ago.
Share & Enjoy!
Code:
Option Compare Binary
Option Explicit
Public Function ScrambleIt(strString As String) As String
'Replace matching case and numbers
'ScrambleIt("Kerkstraat 45, 8194AZ, Baarn")
' "Gibmfwptyi 50, 6491YQ, Jdmfz"
Const cUAlpha As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Const cLAlpha As String = "abcdefghijklmnopqrstuvwxyz"
Const cNum As String = "0123456789"
Dim lngLoop As Long
Dim strNewChar As String
Dim strThisChar As String
Randomize
For lngLoop = 1 To Len(strString)
strThisChar = Mid$(strString, lngLoop, 1)
Select Case strThisChar
Case "a" To "z"
strNewChar = Mid$(cLAlpha, Int(Rnd * Len(cLAlpha)) + 1, 1)
If Asc(strThisChar) > Asc("z") Then strNewChar = Asc("a") + (Asc(strThisChar) - Asc("a") - 1)
Case "A" To "Z"
strNewChar = Mid$(cUAlpha, Int(Rnd * Len(cUAlpha)) + 1, 1)
If Asc(strThisChar) > Asc("Z") Then strNewChar = Asc("A") + (Asc(strThisChar) - Asc("A") - 1)
Case "0" To "9"
strNewChar = Mid$(cNum, Int(Rnd * Len(cNum)) + 1, 1)
If Asc(strThisChar) > Asc("9") Then strNewChar = Asc("0") + (Asc(strThisChar) - Asc("0") - 1)
Case Else
strNewChar = strThisChar
End Select
ScrambleIt = ScrambleIt & strNewChar
Next
End Function
Last edited: