Created
October 21, 2022 15:10
-
-
Save mark05e/4a3208ad0c2d29ca8a74ba1bc0b99a10 to your computer and use it in GitHub Desktop.
Function to return masked string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maskString(inputString){ | |
; Initialize variables | |
returnString := "" | |
maxCharacters := 10 | |
; get first 3 char | |
firstThreeChar := SubStr(inputString, 1, 3) | |
; get last 3 char | |
lastThreeChar := SubStr(inputString, -2, 3) | |
stringLength := StrLen(inputString) | |
if (stringLength > maxCharacters) | |
{ | |
; replace with **...** | |
returnString := firstThreeChar "*** ... ***" lastThreeChar " (" stringLength " characters)" | |
} else { | |
; else return whole string | |
i := 0 | |
middleString := "" | |
Loop | |
{ | |
middleString = %middleString%* ; prepare ***** | |
i := i + 1 | |
} Until i = stringLength | |
returnString := firstThreeChar middleString lastThreeChar | |
} ; if else | |
return returnString | |
} | |
; Tests | |
testString1 := "VGhpcyBpcyBteSBsaWZlIEkgd2lsbCBsaXZlIHRoZSB3YXkgaSB3YW50IHRvIGxpdmUgbWFrZSBtZSBsaXZlIG1vcmU=" | |
testString2 := "This is a line of text" | |
testString3 := "Hello You" | |
Msgbox % maskString(testString1) ; VGh*** ... ***mU= (92 characters) | |
Msgbox % maskString(testString2) ; Thi*** ... ***ext (22 characters) | |
Msgbox % maskString(testString3) ; Hel*********You |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment