- Asterisk Padding
#### → *****#### - Date Formatting
(See the date variable formatting page) - Manual ZIP+4 Formatting
######### → #####-#### - Masking Data
####### → ****### - Phone Number Formatting
########## → (###) ###-#### - Removing Zero Padding
00000#### → #### - Reversing Comma Separated Names
LAST NAME, FIRST NAME → FIRST NAME LAST NAME - Social Security Number Formatting
######### → ###-##-#### - Spelled Out Dollar Amount
123.45 → one hundred twenty three dollars and forty five cents
(See the text variable formatting page) - Zero Padding
#### → 00000#### - Comma Formatting
1234567.00 → 1,234,567.00
(See also the floating point/real/currency formatting page)
Asterisk Padding
(For the purposes of this example, the data to be formatted is stored in a variable named "DATA")
-
Create a new text variable for the padded data.
(PADDED DATA will be used for this example) - Create a function below the variable definition to pad the data:
Result variable = PADDED DATA
Function = Format
Parameter 1 = variable, DATA
Parameter 2 = fixed, %12s
(replace "12" with the desired padding length) -
Create a function below the padding function:
Result variable = PADDED DATA
Function = Regular expression
Parameter 1 = variable, PADDED DATA
Parameter 2 = fixed,- Replace all spaces with asterisks
s/\s/*/g
- Replace leading spaces with asterisks:
s/\G\s/*/g
- Replace all spaces with asterisks
-
PADDED DATA now has the formatted string.
Manual ZIP+4 Formatting
(For the purposes of this example, the data to be formatted is stored in a variable named "ZIP CODE")
-
Create a new text variable for the formatted ZIP code
(FORMATTED ZIP will be used for this example) -
Create a function below the variable definition to format the ZIP code
Result variable = FORMATTED ZIP
Function = Regexp
Parameter 1 = variable, ZIP CODE
Parameter 2 = fixed,s/(\d{5})(\d{4})/$1-$2/
-
FORMATTED ZIP now has the formatted string
Masking Data
(For the purposes of this example, the data to be masked is stored in a variable named "DATA")
-
Create a new text variable for the masked data
(MASKED DATA will be used for this example) -
Create a function below the variable definition to mask the data
Result variable = MASKED DATA
Function = Regexp
Parameter 1 = variable, DATA
Parameter 2 = fixed,s/\G.(?=.{3})/*$1/g
-
MASKED DATA now has the formatted string
Phone Number Formatting
(For the purposes of this example, the data to be formatted is stored in a variable named "PHONE NUMBER")
-
Create a new text variable for the formatted phone number
(FORMATTED PHONE NUMBER will be used for this example) -
Create a function below the variable definition to format the phone number
Result variable = FORMATTED PHONE NUMBER
Function = Regexp
Parameter 1 = variable, PHONE NUMBER
Parameter 2 = fixed,s/(\d{3})(\d{3})(\d{4})/($1) $2-$3/
-
FORMATTED PHONE NUMBER now has the formatted string
Remove Zero Padding
(This can be done directly when defining a text field/variable with the "Remove Zeros" function)
(For the purposes of this example, the data to be formatted is stored in a variable named "DATA")
-
Create a new text variable for the formatted data
(FORMATTED DATA will be used for this example) -
Create a function below the variable definition to format the data
Result variable = FORMATTED DATA
Function = Remove Zeros
Parameter 1 = variable, DATA -
FORMATTED DATA now has the formatted string
Reversing Comma Separated Names
(This can be done directly when defining a text field/variable with the "Reverse Text" function with a "," in the parameter text box to the right of the function drop-down)
(For the purposes of this example, the name to be reversed is stored in a variable named "NAME")
-
Create a new text variable for the reversed name
(REVERSED NAME will be used for this example) -
Create a function below the variable definition to reverse the name
Result variable = REVERSED NAME
Function = Reverse Text
Parameter 1 = variable, NAME
Parameter 2 = fixed, "," -
REVERSED NAME now has the formatted string
Social Security Number Formatting
(For the purposes of this example, the data to be formatted is stored in a variable named "SSN")
-
Create a new text variable for the formatted Social Security number
(FORMATTED SSN will be used for this example) -
Create a function below the variable definition to format the Social Security number
Result variable = FORMATTED SSN
Function = Regexp
Parameter 1 = variable, SSN
Parameter 2 = fixed,s/(\d{3})(\d{2})(\d{4})/$1-$2-$3/
-
FORMATTED SSN now has the formatted string
Zero Padding
(For the purposes of this example, the data to be formatted is stored in a variable named "DATA")
-
Create a new text variable for the padded data.
(PADDED DATA will be used for this example) - Create a function below the variable definition to pad the data:
Result variable = PADDED DATA
Function = Format
Parameter 1 = variable, DATA
Parameter 2 = fixed, %12s
(replace "12" with the desired padding length) -
Create a function below the padding function:
Result variable = PADDED DATA
Function = Regular expression
Parameter 1 = variable, PADDED DATA
Parameter 2 = fixed,- Replace all spaces with zeros
s/\s/0/g
- Replace leading spaces with zeros:
s/\G\s/0/g
- Replace all spaces with zeros
-
PADDED DATA now has the formatted string.
Comma Formatting
(For the purposes of this example, the data to be formatted is stored in a variable named "DATA")
-
Create a new text variable for the formatted data with commas.
(COMMA FORMATTED DATA will be used for this example) - Create a function below the variable definition to pad the data:
Result variable = COMMA FORMATTED DATA
Function = Regular Expression
Parameter 1 = variable, DATA
Parameter 2 = fixed,s/(\d)(?=(?:\d{3})+(?:\.|$))/$1,/g
-
COMMA FORMATTED DATA now has the formatted string.
0 Comments