Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting portion of field after last - 1

Status
Not open for further replies.

GCL2007

IS-IT--Management
Dec 11, 2007
167
US
I have a field that is typically populated in the format 12345-67-890 or something similar to that. There are two - characters, however the number of characters can vary. If I wanted to just get everything after that 2nd - . In the above I would want to report 890, what would be the best way to extract that? It typically would be three characters after that last - , but not always.
Thanks!
 
This will work as long as the field always has exactly 2 "-" characters:

Code:
Split({table.field}, '-')[3]

Hope this helps

Cheers, Pete
 
Thanks Pete.. I'm getting A subscript must be between 1 and the size of the array . Any thoughts?
 
It means the data is not as you believe it to be and there is at least 1 row where there is not two "-" characters.

To fix it you will need to add a test to ignore those rows. Amend the formula to this:

Code:
If      UBound(Split({table.field}, '-')) = 3
Then    Split({table.field}, '-')[3]

Regards
 
Yes - my data wasn't as clean as I hoped... Perfect!! Thank you Again!
 
If you want the report to clearly indicate the data that is not in the expected format you could use something like the following formula:

Code:
If      UBound(Split({table.field}, '-')) = 3
Then    Split({table.field}, '-')[3] 
Else    'Data not in expected format'



Pete.
 
Hi dgillz. If your comment is in regard to my solution, I think you will find it is. As the original field containing the dashes is a string, the split function result is also a string, albeit a numeric string.

All my solutions are tested to avoid typos etc and it did work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top