James Crooke - Web Developer

Cron for Windows IIS

Posted by James on Friday, January 16th, 2009

This is a slightly updated repost of an article I wrote on my old blog. I have had a few requests from people and one from birf to put it back up so here it is;
First, a lesson in the real implementation of cron…
The crontab command, found in Unix operating systems, is used to schedule [...]

continue reading

ASP character trim function

Posted by James on Friday, January 9th, 2009

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@", "@"))

Posted in: Programming.

One Response to “ASP character trim function”

  1. nathan Says:

    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

Leave a Reply