[Gambas-user] Split Strings

Mike Keehan mike_keehan at ...679...
Mon Jan 9 21:04:04 CET 2006


Hi Marcus,

>> mm at ...1313... Wrote
>>> Hi Gambas Users,
>>>
>>> I have got an array containing some string in the following format:
>>>
>>> IPADDR[0]="192.168.1.10"
>>> NETMASK[0]="255.255.255.0"
>>> IPADDR[1]="192.168.10.16"
>>> NETMASK[1]="255.255.255.248"
>>> ...
>>>
>>>
>>> I need to isolete the number within [] and transform it to an integer
>>> variable. Can I use the split command or do I have do use regexp
>>>
>>> Best Regards
>>> Marcus

Split can take multiple separators.  Try something like this:-

   DIM s1 AS String
   DIM Bits AS String[]
   DIM s AS String

   s1 = "name[0]=Marcus"

   Bits = Split(s1, "[]=")

   FOR EACH s IN Bits
     Message("Bit = " & s)
   NEXT

This produces four Message boxes on Gambas 1.0.13,
   1 -> "name"
   2 -> "0"
   3 -> ""
   4 -> "Marcus"

Maybe Benoit can tell us why the 3rd. one is blank :)

Mike.




More information about the User mailing list