Page 1 of 1

Removing certain num of characters from end of string

Posted: Mon Sep 18, 2006 2:51 pm
by opengavel
I can't seem to find a simple way to separate or remove a certain number of characters from the end of a string

I have a group of id numbers (e.g., F001, NY230, IL303, etc.) that are either 4 or 5 characters long. I need to separate the last 3 numerical characters from the remaining 1 or 2 alpha characters. Is there an easy way to trim a string by the location of the characters or by the numeral/alpha difference?

I hunted around for a string function but none seem designed to do this.

Any advice on the shortest and simplist way to accomplish this?

Thanks

Posted: Mon Sep 18, 2006 2:53 pm
by volka

Posted: Mon Sep 18, 2006 2:59 pm
by opengavel
Yikes, I missed that one.

Thanks.

Posted: Mon Sep 18, 2006 3:09 pm
by opengavel
I got it to work with fine with a combination of substr (to get the last 3 chars) and trim (to remove those char, getting the remaining 1 or 2).

Thanks again.

Posted: Mon Sep 18, 2006 3:13 pm
by feyd
trim() shouldn't be needed.

substr($string, 0, -3)