Read first 3 segment of an IP Address and compare it to datatable

hi guys i want to read an ip address from an excel file and compare it to a datatable,
e.g :
an excel cell containing ip address, i read the 10.9.8

another excel file with table :
IP_address | Name
10.9.2 | a
10.9.5 | b
10.9.8 | c

and then in the first excel i write c in the cell next to the ip address

  1. how can i read only the 10.9.8 ?
  2. how do i compare it to the table in another excelf file ?

hi @RobertoEwaldo
I assume you now how to read excel cells.

Question 1
if you have the data of the cell with the whole ip address stored in a variable of type String you can do the following:

  1. Activity “Assign”: indexOfLastPoint = ipAddress.LastIndexOf(“.”)
  2. Activity “Assign” and substring: ipAddressSubstring = ipAddress.Substring(0,indexOfLastPoint)

now ipAddressSubstring contains your 3 segments.
i did some error handling but here is my project.

Question 2:
you can read the range of the 2nd excel data sheet and search for the same ip address.
After that just use the “write cell” activity and you are done.

@madschilos what’s the [0] and [1] in the second answer means ? i get an error like this

@RobertoEwaldo your variable dt should look like:


for each row iterates throught all rows. if you select row[0] its the first column of the row (the ip Adress).
row[1] stands for the letter (for example ‘a’).

the compiler already throws an exception. My guess is ipAddrSubstr is not existing!?

@madschilos i think my problem is with the array, the error is gone when i try to delete the array. can you please check what’s wrong ?
Main.xaml (12.8 KB)

@RobertoEwaldo change your condition to String.Equals(ipAddrSubstr, row(0).ToString())
i am using c# and you are using that was the difference.

@madschilos oh my bad :sweat_smile: thanks it worked bro

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.