How to get the number of lines?

How to get the number of lines returned from a Shell.Execute command?

Var sh As New Shell
sh.Execute(MyCommand)
output = sh.Result
Var lines() As String = output.Split(EndOfLine)
//Var numberOfLines As Integer =  ???

Thanks.

Var numberOfLines As Integer = lines.Count

Or did i missunderstud?

lines.Count

https://documentation.xojo.com/api/language/arrays.html#arrays-count

1 Like

Var sh As New Shell
sh.Execute(MyCommand)
output = sh.Result
Var lines() As String = output.Split(EndOfLine)

Var numberOfLines As Integer = lines.Count

Thanks. Too : Ubound(lines) + 1

Right, “Count” and “UBound” are close (UBound in Xojo is always equal to Count-1).
A good habit would be to use “Count” when showing the value to the user (or if the first element has an index of 1, like AppleEvent items) and use “UBound” when looping or accessing an array (i.e. in code).
Keep both properties separate in your mind, as one or the other is preferred in some circumstances (you avoid adding or removing 1 for no benefit).

UBound has been deprecated in favor of LastIndex

1 Like