ASP character trim function
Happy New Year!
First post of the year, but a quick one.
I was working on an ASP script that required a trim function similar to the PHP
1 | function trim($string, $charset); |
. In PHP, you can start with the word “@apples@” and do
1 | print trim($word, "@"); |
to get “apples” (www.php.net/trim).
In ASP, the trim function doesn’t allow an optional character parameter, so I wrote a character function of my own called “ctrim” that does it;
1 2 3 4 5 6 7 8 9 10 | function ctrim(text, char) if trim(char) = "" then ctrim = trim(text) else text = trim(text) if left(text, len(char)) = char then text = mid(text, len(char)+1, len(text)) end if if right(text, len(char)) = char then text = mid(text, 1, len(text)-len(char)) end if ctrim = text end if end function |
To use it, just use;
1 | response.write(ctrim("@apples@", "@")) |
December 14th, 2009 at 5:16 pm
Hey this was doubtlessly one of the most effective posts I’ve had the chance to go over on the subject so far. I don’t understand where you get all your information but keep it coming! I am going to send a few individuals over here to check this out. Amazing, just plain fantastic. I am have just started getting into spitting out articles myself, nothing compared to your writing skills (lol) but I’d love for you to look over my work in progress sometime! bowflex