How to compare and match string arrays?

Hi All,

I am trying to generate 2 variations of an address using the Suffix abbreviation from USPS website.

So lets say I have the address: 1234 Random Street, I want to make sure that I am generating another variation of this address: 1234 Random St. How do I do this?

This is the website I have to use and I am going to have to utilize all the “Primary street suffix name” and “Postal Service Standard Street abbreviation” from this site: C1 Street Suffix Abbreviations | Postal Explorer

Any help is appreciated!

@dla0313

So you want to search for the string in centre column and create two addresses one with the left column and one with right column?

Cheers

No, you can ignore the center column in the website. Here is an example of what I am trying to do:

Lets say I have an address 1234 Random Street. The suffix “Street” can be found on the left column in that website, so I need to be able to run a match for the word “Street” and find a match in the right column resulting in “St”.

Same thing if the address is 1234 Random St. Then I would need to run a match and find the match for the St which is “Street”.

@dla0313

1 First use table extraction to extract whole of the table
2. now use assign and save the output of this which would be Ienumerable of datarow Ienumdr = dt.AsEnumerable.Where(function(x) System.Text.RegularExpressions.Regex.IsMatch(strAddress,"\b" + x("firstColumn").ToString + "\b"))
3. Now use if activity with Ienumdr.Count>0
4. On the then side you can use assign to replace strAddress = strAddress.Replace(Ienumdr(0)("firstColumn").ToString, Ienumdr(0)("thirdColumn").ToString

Repeat steps 2 to 4 on the else side of the 3rd step with thirdcolumn instead of first column

Hope this helps

Cheers

What if I want to store the values in the config file instead of extracting the table?

Sorry, I didn’t understand this part: Ienumdr. How do I actually type it in the assign activity? IEnumerable(of datarow) = ?

This is throwing an error.

@dla0313

Ypu have to create a variable of type Irnumerable of datarow and us that variable …I names it as Ienumdr

You can store in config as well…but if the table is in website …how are you planning to save the whole table in config?

If you are talking abput address then strAddress is the variable where address is stored

Cheers

Hi,

How about the following sample?

dict = ExtractDataTable.AsEnumerable.Skip(1).GroupBy(Function(r) r(2).ToString).ToDictionary(Function(g) g.Key,Function(g) g.First().Item(0).ToString)

Then

String.Join(" ",yourAddress.Split({" "c}).Select(Function(s) if(dict.ContainsKey(s.ToUpper.TrimEnd("."c)), dict(s.ToUpper.TrimEnd("."c)), s)))

Sample20230501-3aL.zip (4.4 KB)

Regards.

I am not sure, I was thinking of saying it as an array. Also, if the address has something like “Apt 1010” or something in the end, how do you skip over that?

@dla0313

You can use one more condition to address not contain apt 1010 or endswith apt 1010

Cheers

Thank you! I tried this, it worked, but when I tested with an address “1010 Northtown Park Drive”, it updated the word “Park”, and didn’t change the word “Drive” to “Dr”. How do I fix that?

Hi,

Do you need to convert to each other? If so, can you try the following?

dict = ExtractDataTable.AsEnumerable.Skip(1).GroupBy(Function(r) r(2).ToString).ToDictionary(Function(g) g.Key,Function(g) g.First().Item(0).ToString)

dict2 = ExtractDataTable.AsEnumerable.Skip(1).GroupBy(Function(r) r(0).ToString).ToDictionary(Function(g) g.Key,Function(g) g.First().Item(2).ToString)

Then

String.Join(" ",yourAddress.Split({" "c}).Select(Function(s) if(dict.ContainsKey(s.ToUpper.TrimEnd("."c)), dict(s.ToUpper.TrimEnd("."c)), if(dict2.ContainsKey(s.ToUpper.TrimEnd("."c)), dict2(s.ToUpper.TrimEnd("."c)),s))))

Sample20230501-3aLv2.zip (4.4 KB)

Regards,

1 Like

Yes, this works! Thank you!

1 Like

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