Page 1 of 1

StringByteLength

Posted: Mon Jul 08, 2024 10:25 am
by Dirk Geppert
The StringByteLength function is required in particular for string processing in memory, such as Base64 encoding and decoding, if the text contains emojis or other Unicode characters.

Code: Select all

Procedure.i StringByteLength(str.s)
  Protected n.i
    
  !  const encoder = new TextEncoder();
  !  const byteArray = encoder.encode(v_str);
  !  // Die Länge des Byte-Arrays entspricht der Anzahl der Bytes, die der String benötigt
  !  v_n = byteArray.length;
  ProcedureReturn n
EndProcedure


txt.s = RSet(txt, 100, Chr(8211))

Debug Len(txt)

Debug StringByteLength(txt)


Re: StringByteLength

Posted: Thu Jul 11, 2024 5:46 pm
by Quin
+1
Nice function by the way, it works great. Thanks for introducing me to TextEncoder :)

Re: StringByteLength

Posted: Fri Jul 12, 2024 4:13 am
by juror
Another +1

Thanks for sharing