Desktop productivity for business analysts and programmers

Parse data starting from the right of string

Reply
Contributor
Posts: 55

Parse data starting from the right of string

Hi all,

 

I have a field with string values than have various ranges of length. I want to extract an ID hidden within the string, and it seems that it will be the same character distance from the right side of the string, so instead of doing substr from the left side, I want to start counting back from the right.

 

Also, I should note that even though it seems to be consistently the same distance from the right, there are a few values  at the end that I want removed, so I imagine I'd have to specify the number of characters to bring back.  

 

Here is what the field value looks like, I want to extract the the part of the string that is in bold. Let's assume this field is called "code".

 

alamessage_email_announcenews_NA_PR_20170301_cta_OP00423231412210381PR_M-M32321771C

Super User
Posts: 22,827

Re: Parse data starting from the right of string

REVERSE() function will reverse the string.

SCAN() with negative numbers will extract from the right of the string. 

I don't recall if SUBSTR() takes negative numbers, you can look into that

LENGTH() will return the length of the string if that's required.

 

One data point isn't helpful for generating a rule. 

 


schlotty23 wrote:

Hi all,

 

I have a field with string values than have various ranges of length. I want to extract an ID hidden within the string, and it seems that it will be the same character distance from the right side of the string, so instead of doing substr from the left side, I want to start counting back from the right.

 

Also, I should note that even though it seems to be consistently the same distance from the right, there are a few values  at the end that I want removed, so I imagine I'd have to specify the number of characters to bring back.  

 

Here is what the field value looks like, I want to extract the the part of the string that is in bold. Let's assume this field is called "code".

 

alamessage_email_announcenews_NA_PR_20170301_cta_OP00423231412210381PR_M-M32321771C


 

Super User
Posts: 6,536

Re: Parse data starting from the right of string

[ Edited ]

Perhaps easiest:

 

length ID $ 15;

ID = substr(code, length(code)-30);

 

That's assuming that I counted properly and there are 15 "characters to be ignored" at the end, as well as 15 characters in ID.

Ask a Question
Discussion stats
  • 2 replies
  • 132 views
  • 0 likes
  • 3 in conversation