How should I split an address to fill different fields

How should I split an address to fill different fields. i am currently getting the full address in one field and would like to split it into a few different fields.

example:
from one field
FAIRFAX, VA 22030
to
FAIRFAX
VA
22030
all as separate items

I would suggest that you use the Split Activity with a single white space as the separator. This will give you an array of strings with {“FAIRFAX,”, “VA”,“22030”} as the values. Then you call String.Remove() on the first value to get rid of the comma. See Attached
String Manip.xaml (7.3 KB)

Thanks, that’s very helpful. I do have a followup question. In the case of the city having a space in between(ex. New York) it is cutting out the w in New and leaving the comma after York. Do you know what would cause this?

@mbpatter

That is because the array would now have an extra value.
FAIRFAX, VA 22030 would lead to {“FAIRFAX,”, “VA”,“22030”}
New York, NY, 10065 would lead to {“New”, “York,”, “NY”, “10065”}
You would have to configure the workflow to accept the last word of a multi-word named city on which to perform the remove method. I would do this by using the index (arr.count - 3)

You could do this by storing each value individually and using the comma:

city = address.Trim.Split(","c)(0)
state = address.Trim.Split(","c)(1).Split(" "c)(0)
zip = address.Trim.Split(","c)(1).Split(" "c)(1)

You can also use a Regex pattern but I will just present the .Split method.

There could be other ways to.

Regards.

Hi @DavidV32,
Here I have attached the sample to split the City , state and zip. It has excel that you can able to test to add more data.

File : Split an address.zip (7.9 KB)

Regards
Balamurugan

Parsing is an age old skill, not RPA specific.

The trick is to start with what you know and back into what you don’t.
So the first thing you have to know is what your input patterns will be.

If you are always receiving <city>, <two char state> <zip>, then you can use split with whitespace, pull the last item as the zip, the next to last item as state code and then concatenate all the previous ones and drop the comma (if exists). That way you can catch whatever city name you get, no matter how many spaces.

If your input format has more variability than that, you may need to think through your algorithm a little more.

Happy parsing.

Scott

What is this “c” here?

Hi @Deepan_DB

The .Split() function requires a character or a character array. The “c” stands for character so it’s basically just converting the string to a character… it’s the equivalent of taking the first character of the string like an array (ie .Split(“,”(0)) and .Split(","c) are the same ).

In the situation where you might want to remove empty entrees or split by more than one character, then you need to use it like an array of characters (ie .Split({“,”},System.StringSplitOptions.RemoveEmptyEntrees) )

Regards.

1 Like

Thanks it worked…