How to get the length of a string literal?

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


doesn’t work. Do I have to use a constant or property in API2?

  1. the old style which still works
  2. stuff it in a variable first then use Length on that variable


in modul global method :slight_smile: but i would still use Len in your case

[code]Public Function Length(s As String) as Integer
Return s.Length

End Function

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.