[Gambas-user] Split-Method

Tobias Boege taboege at gmail.com
Mon Feb 5 21:56:09 CET 2018


On Mon, 05 Feb 2018, Hans Lehmann wrote:
> Hello,
> 
> when I use this string 'sLine' :
> 
> ^Property^Data type^Description^
> 
> then I get a totally wrong result:
> 
>        ' Number of columns in the table
> 
>          iColumnCounter = Split(sLine,"^").Count
>          Print iColumnCounter
> 
> The result is 5, which is due to UTF8 and the character ^?
> 
> How do I get the correct result 3?
> 

I don't think it has anything to do with UTF8. In my opinion, the result
is even correct. The result of your Split is the array

  ["", "Property", "Data type", "Description", ""]

For example in the string "^Property", you have the empty string "" and
the string "Property" separated by the caret "^", so splitting by "^"
will give you the left part (the empty string) and the right part (the
"Property" string). The same happens at the end of your string.

Split() has a convenience option IgnoreVoid which lets you discard empty
strings, see the documentation [1].

Regards,
Tobi

[1] http://gambaswiki.org/wiki/lang/split

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list