Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/String-length/M2000-Interpreter/string-length.m2000
Normal file
28
Task/String-length/M2000-Interpreter/string-length.m2000
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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
|
||||
\\ Write at memory at offset 0 or address Mem(0)
|
||||
Return Mem, 0:=A$
|
||||
Print Eval$(Mem, 0, 18)
|
||||
For i=0 to 17 step 2
|
||||
\\ print hex value and character
|
||||
Hex Eval(Mem, i as integer), ChrCode$(Eval(Mem, i as integer))
|
||||
Next i
|
||||
Document B$=A$
|
||||
\\ encode to utf-8 with BOM (3 bytes 0xEF,0xBB,0xBF)
|
||||
Save.Doc B$, "Checklen.doc", 2
|
||||
Print Filelen("Checklen.doc")=17
|
||||
\\ So length is 14 bytes + 3 the BOM
|
||||
Mem=Buffer("Checklen.doc")
|
||||
Print len(Mem)=17 // len works for buffers too - unit byte
|
||||
// version 12 can handle strings without suffix $
|
||||
C=eval$(mem, 3, 14) // from 4th byte get 14 bytes in a string
|
||||
Print len(C)*2=14 ' bytes // len()) for strings return double type of words (can return 0.5)
|
||||
C=string$(C as utf8dec) ' decode bytes from utf8 to utf16LE
|
||||
Print len(C)=9, C=A$, Len.Disp(C)=4
|
||||
Print C
|
||||
Report 2, C // proportional print on console - for text center justified rendering (2 - center)
|
||||
}
|
||||
String_length
|
||||
Loading…
Add table
Add a link
Reference in a new issue