Size of a string stored in variable

Hello,

Is there a way to get the size of a string stored in a variable?
Something like below.

LET#TEXT 'Some text'
     TXB SIZEOF(#TEXT )  $not CADINP

In cadinp every 8 characters are stored as one element in array, so you can measure length of string with 8 chars accuracy

prog template urs:1
head
sto#A ‘12345678’
sto#B ‘1234567812345678’
sto#C ‘123456781234567812345678’
sto#D ‘12345678123456781234567812345678’

end

+prog template urs:2
head
loop#i A
endloop
txb A length is #(8*(#i-1)) - #(8*(#i))

loop#i B
endloop
txb B length is #(8*(#i-1)) - #(8*(#i))

loop#i C
endloop
txb C length is #(8*(#i-1)) - #(8*(#i))

loop#i D
endloop
txb D length is #(8*(#i-1)) - #(8*(#i))

end

Hello @mico,

Nice idea, but the result is not precise enough.

For precise evaluation you have to go beyond cadinp input. Code below should work like magic:

+prog template urs:3
head
sto#TEST ‘ABCDEFGHIJK’
<text,file=stringlen.txt>
#TEST
< /text>
<text,file=testlen.dat>
txb
< /text>
del#length
<text,file=stringlen.vbs>
Set objFSO=CreateObject(‘“Scripting.FileSystemObject”’)
set objFile=objFSO.OpenTextFile(‘“stringlen.txt”’)
strCharacters=objFile.ReadAll
strCharacters=Replace(strCharacters,vbCrLf,‘“”’)
Wscript.Echo ‘“prog template”’
Wscript.Echo ‘"sto#length "’ & Len(strCharacters)
Wscript.Echo ‘“end”’
objFile.Close
< /text>
<text,file=stringlen.bat>
del testlen.dat
cscript /nologo stringlen.vbs > testlen.dat
< /text>
end
+sys stringlen.bat
+apply testlen.dat
+prog template urs:4
head
txb size(TEST) = #length
end

you need to remove space from < /text>

1 Like

That is nice )))