<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > !STR.- String Command > String Operations |
MiniRobotLanguage (MRL)
STR.TO BASE64 URL
String commands
Intention
To transfer binary data in written form, all "non-printable characters" like ASCII 12,13 and others need to be encoded in printable Form.
For this generally the MIME-Format can be used. The MIME-Format is also called "BASE 64" Format. There is a special case where we do not want to have "+" and "/" signs in the result. This is the so called "BASE64 URL-Format".
STR.TO BASE64 URL will convert the text or binary data that is contained in a variable, to the BASE64 URL-Format. The result will be in the same variable or in a Target variable if given.
The command itself looks like this:
' $$SRC - Binary or Text-Data to convert to MIME
' $$TAR - MIME-Format Result
STR.TO BASE64 URL|$$SRC|$$TAR
The Result looks somehow like you see below.
Its a Screenshot from the Examples below (see Examples-Section).
As you can see the MIME encoded Binary is 360 bytes long, while the original size was 270 bytes. That is generally 134% the size of the original size.
There is an additional third parameter, that allows for a maximum line-length, after which a $crlf$ will be inserted (newline). If this parameter is zero, no $crlf$ will be inserted. Otherwise, it may look like this:
STR.TO BASE64 URL|$$SRC|$$TAR|24
or
STR.TO BASE64 URL|$$SRC||24
The Result now contains a linefeed ($crlf$) after each line with the given number of characters.
Now the Ratio is 144% because of the additional Newlines that have been added.
They will be ignored when decoding MIME back to the original Text or Binary.
This is the reverse command to STR.FROM BASE64 URL.
Syntax
STR.TO BASE64 URL|P1[|P2][|P3]
Parameter Explanation
P1 - source variable. If P2 is missing then its also the destination variable
P2 - (optional) destination variable. If omitted the result is placed in the variable in P1.
P3 - (optional) numerical parameter. If given, a $crlf$ (Newline) is placed after the given number of characters.
Example
'*************************************
' STR.TO BASE64 URL and
' STR.FROM BASE64 URL
' using one Input-Output-Variable
'*************************************
$$SRC=What happens under BASE64 with the + and / Characters?
$$SRC=$$SRC$$SRC$$SRC$$SRC$$SRC
LEN.$$SRC|$$LEN
PRT.($$LEN)->$$SRC
STR.TO BASE64 URL|$$SRC
LEN.$$SRC|$$LEN
PRT.($$LEN)->$$SRC
STR.FROM BASE64 URL|$$SRC
LEN.$$SRC|$$LEN
PRT.($$LEN)->$$SRC
MBX.It works!
$$SRC=What happens under BASE64 with the + and / Characters?
$$SRC=$$SRC$$SRC$$SRC$$SRC
LEN.$$SRC|$$LEN
PRT.($$LEN)->$$SRC
STR.TO BASE64 URL|$$SRC||24
LEN.$$SRC|$$LEN
PRT.($$LEN)->$$SRC
STR.FROM BASE64 URL|$$SRC
LEN.$$SRC|$$LEN
PRT.($$LEN)->$$SRC
MBX.It works!
ENR.
Remarks
-
Limitations:
-
See also:
• 1.5.2 Working with Text-Strings
• VAR. - Variable Set Value/Clear
• IVS. / NVS. - If-Variable-String