Extract/parse last 3 characters of string?

Hi community! I have been reading the forums and have run into an issue I am unable to find a resolution.

We have an address field and want to essentially take the country code to utilize in our TMSCommercialInvoice.Report for the country of origin.

Is there a function to pull out only the last 3 values of this field?

image

Hi @spare,

Welcome to the forum!

There are several ways to solve this using an XPath 1.0 expression.

If you want to always extract the last 3 characters, you can use a combination of the substring() and string-length() functions in XPath. It would look something like this:

substring(//PSAProjInvoiceHeader/@Address, string-length(//PSAProjInvoiceHeader/@Address) - 2)

A more flexible approach might be to use the substring-after() XPath 1.0 function to extract all the values before the last newline character. Since the address contains line feeds, this will help determine when the address should move to a new line, ensuring the correct format. This method isn’t limited to just 3 characters; it could work with any number of characters and will still function correctly.

substring-after(substring-after(PSAProjInvoiceHeader/@Address,$lf),$lf)

Try it out and let me know how it goes.

Thank you for the explanation - this worked perfectly!