Problem with Regex.split (I think)

moster67

Expert
Licensed User
Longtime User
I have an ip-address which I want to split in 4 octets. I get the ip-address using the network-library. The problem is that I can't, using Regex.split, split the ip-address by using a dot (.) as pattern.

Here is my code:

B4X:
Dim mynetwork As ServerSocket
Dim DeviceIpAddress As String

DeviceIpAddress=mynetwork.GetMyIP 'GetMyIp returns a string-value.  
                                              'Let us say - 192.168.1.4

'now split ip-address in 4 octets
   
Dim myOctets As List
myOctets.Initialize
   
myOctets=Regex.Split(".",DeviceIpAddress)
   
For x = 0 To myOctets.Size -1
   Msgbox(myOctets.Get(x),"")
Next

Instead of a List, I tried using an array but there is no difference.

The problem is in this line:

B4X:
myOctets=Regex.Split(".",DeviceIpAddress)

myOctets is always = 0

Perhaps I am using Regex.split not in the correct manner.

Can anyone help to get this to work? Thanks.
 

stevel05

Expert
Licensed User
Longtime User
The "." needs escaping, try "\."
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Thanks guys! That resolved my problem.

I had no idea that the dot was a special character. Any other characters I should watch out for?
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
OK - I will keep that in mind when using RegEx next time.

Thanks!
 
Upvote 0

Similar Threads

Top