In the good old times I made code like this:
dim s as Integer = len("test")
I know that I should do constants and what not. But sometimes I don’t want to. How do I do this in API2? A
"test".length
doesn’t work. Do I have to use a constant or property in API2?
the old style which still works
stuff it in a variable first then use Length on that variable
<https://xojo.com/issue/56629 >
MarkusR
(MarkusR)
October 20, 2019, 3:17pm
3
in modul global method but i would still use Len in your case
[code]Public Function Length(s As String) as Integer
Return s.Length
End Function
[/code]
Extra lines
Var Test as String = "TEST"
Var s As Integer = Test.Lenght
Thanks, guys. The Feedback case from Norman is the one I want.
dim s as Integer = Ctype(“test”, String).Length also works for literals or constants.
Using CType is possible but verbose and slow. We should really be able to either use a global Len/Length function or a “xxx”.length form with the compiler optimising the code.