Mask
Function
The mask_inner
and mask_outer
functions are used to replace parts of a string, typically to hide sensitive information such as passwords, phone numbers, etc. The mask_inner
function retains the characters at both ends of the string with lengths margin1
and margin2
, while replacing the middle part with a specified mask character (default is 'X'). The mask_outer
function masks the characters at both ends of the string with lengths margin1
and margin2
, retaining the middle part.
Parameter Description
str
: The original string to be processed.margin1
: The number of characters to retain or mask on the left end.margin2
: The number of characters to retain or mask on the right end.mask_char
(optional): The mask character used to replace the middle part of the string, default is 'X'.
Return Value
Returns the processed string.
Usage Example
By the above example, you can flexibly use the mask_inner
and mask_outer
functions according to actual needs to protect users' privacy information.