SnippetsBase64StringEncoder

Snippets

Base64StringEncoderConstants for numeric limitsDelayMicroSecondsElapsedTimeMD5ModuloRandomFloat

Base64StringEncoderFUNCTION

Descrition

Gives the Base64 encoded string of given string.

Syntax

EncodedString.s = Base64StringEncoder( String.s [, Mode.i] )

Parameter

String The string for the encoding.
Flags The mode of the string to calculate the Base64:
#PB_Ascii All characters uses 1 byte.
#PB_Unicode All characters uses 2 bytes.
#PB_UTF8 Characters uses 1 to 4 bytes (default mode).

Return value

The Base64 encoded string.

Snippet

Procedure.s Base64StringEncoder(String.s, Mode.i=#PB_UTF8)
  
  Protected Length.i, Result.s
  Protected *Source = AllocateMemory(StringByteLength(String, Mode))
  Protected *Destination = AllocateMemory(StringByteLength(String, Mode)*1.35+64)
  
  If *Source And *Destination
    PokeS(*Source, String, Len(String), Mode|#PB_String_NoZero)
    Length = Base64Encoder(*Source, MemorySize(*Source), *Destination, MemorySize(*Destination))
    Result = PeekS(*Destination, Length, #PB_Ascii)
    FreeMemory(*Source)
    FreeMemory(*Destination)
  EndIf
  
  ProcedureReturn Result
  
EndProcedure

Example

Debug Base64StringEncoder("Äpfel", #PB_Ascii)
Debug Base64StringEncoder("Äpfel", #PB_UTF8)
Debug Base64StringEncoder("Äpfel", #PB_Unicode)
xHBmZWw=
w4RwZmVs
xABwAGYAZQBsAA==
Union Bytes | Login