[Gambas-user] Split-Method

Charlie Ogier charlie at cogier.com
Tue Feb 6 16:01:02 CET 2018


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
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180206/d79b956f/attachment.html>


More information about the User mailing list