Selecting a range of items in an array

Hey there team, hope all is well!! I’ve built a data table with the table headers for Address, City, State, Ziip Code.
I have the following address:
123 Main Street SomeTown, NY 12345
What i did is split the string by space, so basically: newArr = myString.Split(" ",c)
I’m working backwards, the last index is the zip code, so i use an Update Row Item activity for the Zipcode Column, then the same for City and State. But i would like to just take whatever items in the array from 0 to just before the City to place in the Address Column. How can i do this? Appreciate your help in advance!!

Hi @olmccb ,

You may try this approach:

varAddress = “123 Main Street SomeTown, NY 12345”
varStreet = varAddress.Split(“Street”)(0).ToString+“Street”
varCity = (varAddress.Split(“Street”)(1).ToString).Split(", “)(0)
varState = (varAddress.Split(“Street”)(1).ToString).Split(”, “)(1).Split(” “)(0)
varZipCode = (varAddress.Split(“Street”)(1).ToString).Split(”, “)(1).Split(” ")(1)

Hope this helps. Happy automation!

Kind regards,
Kenneth

@kennbalobalo thank you very much for your reply, i really appreciate it!! But here is the that i am running into. The address that i gave was just an example, right:
123 Main Street, Sometown, NY 12345 but it could also be
123 Main Street Apt# 1, Sometown, NY 12345 or also
123 Main Street Ste #1, Sometown, NY 12345
You see, i know for sure that the last three array items are always going to be zip, state and city and whatever is left i just want to be able to throw under the Address column.
Thank you in advance for your help!
Ingrid

Hi @olmccb ,

Then we can also do this approach:

myArray = myString.Split({“,”, “,”}, StringSplitOptions.None)

strAddress = myArray(0).Trim
strCity = myArrary(1).Trim
strState = (myArrary(2).Trim).Split(" “c)(0)
strZipCode = (myArrary(2).Trim).Split(” "c)(1)

I have also attached a sample code for your reference.

GetAddress.xaml (7.6 KB)

I hope this helps. Happy automation!

Kind regards,
Kenneth

hey there @kennbalobalo thank you once again.

  • so i tried to open your xaml and i got a message saying the file was invalid

  • I get this error mesesage
    image

  • this is what i have in my editor

Hi,

Is there always comma just before City? if so the following will work.

m = System.Text.RegularExpressions.Regex.Match(yourString,"(?<ADDRESS>.*),\s*(?<CITY>.*?)[\s,]+(?<STATE>\S+)[\s,]+(?<ZIP>\d+)$",System.Text.RegularExpressions.RegexOptions.RightToLeft)

Then

m.Groups("ZIP").Value
m.Groups("STATE").Value
m.Groups("CITY").Value
m.Groups("ADDRESS").Value

Sample20230209-5L.zip (2.4 KB)

If there is NOT always comma just before city, we need to find a way to identify city name, because city name might be include whitespace such as “Los Angels” and we cannot use split whitespace simply.

Regards,

hi @olmccb ,

Let me reshare the whole project:
GetAddress.zip (2.5 KB)

For the editor error, try retyping it.

Kind regards,
Kenneth

Appreciate you @kennbalobalo !!

1 Like

Hi there @Yoichi , normally 99% of the time there is a comma before after the city. I see what you mean…about the city containing a white space…and that’s why i just wanted to join and drop any array items after identifying city, state and zip into the address column
Thank you once again for your support I really appreciate it!!! Wish UiPath had that feature about buying your guys a cup of coffee!! I would buy you guys a nice steak diner! :meat_on_bone::fried_shrimp:

@kennbalobalo i owe you a steak dinner too!! tell me where to send GrubHub​:meat_on_bone::fried_shrimp:!! Much love to you all!! Thank you the file opened up!

1 Like

Hi,

If you need to handle remaining 1%, might be able to use Zip to Address database.
In this case, we can easily get Zip code, then obtain state and city from the above.

https://tools.usps.com/zip-code-lookup.htm?citybyzipcode

Regards,

1 Like

Glad to know that the file opened up now. :slightly_smiling_face: happy to help and contribute to the community! :smile:

1 Like

Yup tell me where to send your GrubHub :grinning:

Both @Yoichi and @kennbalobalo, you both helped me solve the same issue with two differnt appraoched but i guess i can only choose one of you :sob: Please dont get mad!

I’m in Singapore right now. So no worries, it’s all fine. I’m happy that your problem is solved.

1 Like

@kennbalobalo I hate to be here again but i ran the file on my address and i got an out of bounds error…and i didnt understand but then i realized that you put in a comma right before the city: but there shouldn’t be a comma there and i noticed that i made that mistake. Apologies for that i tried to remove the comma in the expression and replace it with a space but it didnt work. I’m so sorry for that I don’t know why i did it
image

hi @olmccb ,

The text I used is based from the samples you shared earlier:
123 Main Street, Sometown, NY 12345 but it could also be
123 Main Street Apt# 1, Sometown, NY 12345 or also
123 Main Street Ste #1, Sometown, NY 12345

I assumed that there’s always a comma right before the City that’s why I used the two commas as separators. Hope this clears things up.

yes i know and i apologize there shouldn’t have been a comma, sorry.

no worries. can you send a sample add so I can update the code and share it with you?

1 Like

Hi @olmccb ,

I’m attaching here the updated project. Kindly open the GetAddress-Updated.xaml which works on the address without commas.

GetAddress.zip (4.5 KB)

I hope this helps. Happy automation!

Kind regards,
Kenneth

1 Like