Skip to main content
Solved

how to extract the last two characters in a string?

  • December 9, 2025
  • 7 replies
  • 104 views

vxn43
Supporter
Forum|alt.badge.img+18

I have a field with city names and state names in this format:

Oklahoma City OK

Oakland CA

Dallas TX

Forth Worth TX

Augusta ME

 

 

I want to do the following:

Extract the City name into one field and the state abbreviation into another field.

 

The only consistent pattern in the data is the state abbreviation always comes after the last space in the string.

 

I think I need to create a RegEx expression to do be able to do this.

 

Can someone help me with how do this?

 

Best answer by DanAtSafe

Hi ​@vxn43 Two SubstringExtractors might be easiest if the format is always <city name><space><state abbreviation>

 

7 replies

DanAtSafe
Safer
Forum|alt.badge.img+22
  • Safer
  • Best Answer
  • December 9, 2025

Hi ​@vxn43 Two SubstringExtractors might be easiest if the format is always <city name><space><state abbreviation>

 


sammy
Supporter
Forum|alt.badge.img+24
  • Supporter
  • December 9, 2025

Edit: I got my statements wrong and can’t seem to update this post...

 

 You can also do what ​@DanAtSafe suggested within the Attribute Manager if creating two new attributes:

City Name: @Substring(@Value(Original Data),0,-2)

State: @Substring(@Value(Original Data),-2,2)

 


sammy
Supporter
Forum|alt.badge.img+24
  • Supporter
  • December 9, 2025

I don’t know if this is the most efficient way to do this but it works if the data will always be structured as you say <city Name> <space> <two letter state abbreviation>.

In an attribute manager you can create two new attributes and input the following in the text editor for the values:

For City Name:  “@Left(@Value(<your original column>),(@StringLength(@Value(<your original column>))-3))”

For State:  “@Substring(@Value(<your original column>),-2,2)”

 

Someone else may have a cleaner way of getting the City Name. I tried using @Substring(@Value(<your original column>),0,-3) but it did not work.


danilo_fme
Celebrity
Forum|alt.badge.img+52
  • Celebrity
  • December 10, 2025

Hi ​@vxn43 Two SubstringExtractors might be easiest if the format is always <city name><space><state abbreviation>

 

Good Job ​@DanAtSafe 


salvaleonrp
Enthusiast
Forum|alt.badge.img+20
  • Enthusiast
  • December 10, 2025

@danilo_fme I love the font… Ink free?


DanAtSafe
Safer
Forum|alt.badge.img+22
  • Safer
  • December 10, 2025

@salvaleonrp 😉Yes, it’s Ink Free.


danilo_fme
Celebrity
Forum|alt.badge.img+52
  • Celebrity
  • December 10, 2025

@danilo_fme I love the font… Ink free?

Yep ​@salvaleonrp