Strdecode

This function transforms a UTF8 or ASCII encoded character string (based on the parameter given) into a UCS2 format. It returns the number of character found in the destination.

Syntax

STRING_LENGTH=StrDecode(STRING_SOURCE,STRING_DESTINATION,TYPE)

Any other given value will trigger an error.

Example

# Let's transcode a character string from one format to another# SOURCE_FORMAT should be "ASCII", "UCS2",or "UTF8"# DESTINATION_FORMAT should be "ASCII", "UCS2",or "UTF8"Funprog TRANSCODE(SOURCE, SOURCE_FORMAT, DESTINATION,DESTINATION_FORMAT)Const Clbfile SOURCEVariable ClbFile DESTINATIONConst Char SOURCE_FORMAT,DESTINATION_FORMATLocal Integer I# Let's first look if the format is the sameIf toupper(SOURCE_FORMAT)=toupper(DESTINATION_FORMAT)DESTINATION=SOURCEEnd len(DESTINATION)Endif# Now let's use one or two transcodingsCase toupper(SOURCE_FORMAT)-toupper(DESTINATION_FORMAT)When "ASCII UCS2" : I=strDecode(SOURCE,DESTINATION,50)When "UTF8 UCS2" : I=strDecode(SOURCE,DESTINATION,0)When "UCS2 ASCII" : I=strEncode(SOURCE,DESTINATION,50)When "UCS2 UTF8" : I=strEncode(SOURCE,DESTINATION,0)When Default : Local Integer ISIZEISIZE=max(0,int(1+log(max(1,len(SOURCE)+1))/log(2))-9)Local Clbfile INTERMEDIATE(ISIZE)Case toupper(SOURCE_FORMAT)-toupper(DESTINATION_FORMAT)When "ASCII UTF8" : I=strDecode(SOURCE,INTERMEDIATE,50)I=strEncode(INTERMEDIATE,DESTINATION,0)When "UTF8 ASCII" : I=strDecode(SOURCE,INTERMEDIATE,0)I=strEncode(INTERMEDIATE,DESTINATION,50)When Default : # Unknown conversionEnd -1EndcaseEndcaseEnd I

See also

B64Decode, B64Encode, strEncode