[Gambas-user] Split-Method

Gianluigi bagonergi at gmail.com
Tue Feb 6 16:27:39 CET 2018


No Charlie,
I think Tobias intended to suggest this:

Public Sub Main()

  Dim s As String = "^Property^Data type^Description^"
  Dim ss As String[]

  ss = Split(s, "^", Null, True)
  Print ss.Count

End

Regards
Gianluigi

2018-02-06 16:01 GMT+01:00 Charlie Ogier <charlie at cogier.com>:

> I agree with Tobi. I tried this which gives the correct answer: -
>
> *Public Sub Main()*
> *Dim sLine As String = "Property^Data type^Description"*
>
> *Print Split(sLine, "^").Count*
>
> *End*
>
> Charlie
>
> On 05/02/18 20:56, Tobias Boege wrote:
>
> 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
>
>
>
>
> --------------------------------------------------
>
> This is the Gambas Mailing List:
> https://lists.gambas-basic.org/listinfo/user
>
> Search the list:
> https://lists.gambas-basic.org/cgi-bin/search.cgi
>
> Hosted by https://www.hostsharing.net
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180206/bac39bca/attachment.html>


More information about the User mailing list