Splitting House Numbers with letters

I’m processing some data where I have house numbers stored in a String named houseNumber. Usually they are just digits, but sometimes they might have a letter after the number. E.G 1a, 1b, 1c etc…

I want to split houseNumber into two strings. houseNumberNum and houseNumberLet, so in the case of houseNumber being 26b, houseNumberNum would be ‘26’ and houseNumberLet would be ‘b’

I’ve tried various regular expressions with split, but thus far I’ve had no success. Can anyone help please? TIA!

1 Like

Try this one

1 Like

hey @andrewjames

try this,

To get only Numbers/ digits from a string
System.Text.RegularExpressions.Regex.Replace(yourString,"\D","")

To get only Alphabets(case insensitive), from a string
System.Text.RegularExpressions.Regex.Replace(yourString, “[^a-z A-Z]”, “”)

Let me know if this helped.

Thanks,
Chandan

6 Likes

Capital D gets anything, but numbers. Lowercase d is for numbers.

3 Likes

Using Capital D gives me numbers only, which is desired in this case.
Using lowercase d gives me alphabets only.

We are on same page. correct?

1 Like

Thank you! All sorted now!

1 Like

Using D will get the Non-Digits , which are getting replaced with NULL
So remaining data will be Numbers only.

1 Like

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