RosettaCodeData/Task/String-length/M2000-Interpreter/string-length.m2000

22 lines
698 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
module String_length {
A$=format$("J\u0332o\u0332s\u0332e\u0301\u0332")
Print Len(A$) = 9 ' true Utf-16LE
Print Len.Disp(A$) = 4 \\ display length
Buffer Clear Mem as Byte*100
2026-04-30 12:34:36 -04:00
Buffer Mem2 as Integer*50
Mem[0]=A$
Print Eval$(Mem, 0, 18) ' 18 bytes from Mem[0] as a string
Mem2[0]=Mem
For i=0 to 8
Hex Mem2[i], ChrCode$(Mem2[i])
2023-07-01 11:58:00 -04:00
Next i
2026-04-30 12:34:36 -04:00
// Check as UTF8 (UTFEnc and UTF8Dec are selections for string$())
Print len(string$(A$ as UTF8Enc))*2=14 ' bytes
Locale 1033
// to ANSI and back to UTF16LE (destructive)
Print chr$(str$(A$))="J_o_s_e´_" ' true
Print A$;POS=4 ' J̲o̲s̲é̲True
Print String$(A$ as Json)="J\u0332o\u0332s\u0332e\u0301\u0332" ' True
2023-07-01 11:58:00 -04:00
}
String_length