Separate street name from street number

Example address: “New York Avenue 12 3544 NYC”
This address is represented as a string.

The output I am trying to achieve is the following:

Address Name: New York Avenue
Address Number: 12
Zip Code: 3544
District: NYC

I was thinking of splitting the string based on the spaces present, but since some street names have multiple spaces in their name, this wasn’t possible.

A possible solution I am thinking of is finding the position of the first occurring number in the string, being the street number, and splitting the string from there, seperating the street name from the street number.
However, I have no clue on how to do this. I am having troubles seperating letter from the number values in order to achieve that goal.

Thanks in advance

1 Like

I don’t know if this will answer it fully, but you can use Regex.Match().Value to pull out the text based on a pattern.

(I’m just going to wing it on the pattern)


Then, you can split that Value by spaces to get Number, Zip, and District, so…
System.Text.RegularExpressions.Regex.Match(address,“((\d{5,6})|(\d{3,4})|(\d{1,2}))\s((\d{5,6})|(\d{3,4}))\s(.*)”).Value.Trim.Split(" "c)(0)

And, you can use the same thing to remove it and get the Name.

I’m no expert on Regex but to make sure I tested the above examples and they seemed to work for me.