• truncsp() for beginnings of strings?

    From art@FATCATS to All on Tue Nov 17 09:48:22 2009
    Hi all,

    Is there a way to trim whitespaces at the beginning of strings, like truncsp()?

    Regards,
    Art at fatcats dot poorcoding dot com

    | fatcats bbs |
    | + telnet://fatcats.poorcoding.com |
    | + ssh://fatcats.poorcoding.com:2322 |

    ---
    ■ Synchronet ■ fatcats bbs - http://fatcats.poorcoding.com
  • From Deuce@SYNCNIX to art on Tue Nov 17 09:46:29 2009
    Re: truncsp() for beginnings of strings?
    By: art to All on Tue Nov 17 2009 09:48 am

    Is there a way to trim whitespaces at the beginning of strings, like truncsp()?

    str=str.replace(/^\s*/, '');

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From Tracker1@TRN to art on Tue Nov 17 22:19:59 2009
    On 11/17/2009 2:48 AM, art wrote:
    Hi all,

    Is there a way to trim whitespaces at the beginning of strings, like truncsp()?

    //include this somewhere...
    String.prototype.trim = function() {
    return this.replace(/^[\s\r\n]+|[\s\r\n]+$/g, '');
    }
    String.prototype.ltrin = function() {
    return this.replace(/^[\s\r\n]+/g, '');
    }
    String.prototype.ltrin = function() {
    return this.replace(/[\s\r\n]+$/g, '');
    }

    now you can use yourstring.ltrim()

    --
    Michael J. Ryan - http://tracker1.info/

    ... B5: Then what kind of head of security would I be if I let people like me know things that I'm not supposed to know? I know what I know because I have to know it. And if I don't have to know it, I don't tell me, and I don't let anyone else tell me either.

    ---
    ■ Synchronet ■ Roughneck BBS - telnet://roughneckbbs.com - www.roughneckbbs.com
  • From art@FATCATS to Tracker1 on Wed Nov 18 08:53:45 2009
    Re: Re: truncsp() for beginnings of strings?
    By: Tracker1 to art on Tue Nov 17 2009 22:19:59

    now you can use yourstring.ltrim()

    Thanks Deuce and Tracker1...

    I was hoping I wouldn't need to regexp it and it was provided as part of JSOM, however I'll likely implement a function as you guys have provided the regexp for, thanks.

    Regs,
    Art at fatcats dot poorcoding dot com

    | fatcats bbs |
    | + telnet://fatcats.poorcoding.com |
    | + ssh://fatcats.poorcoding.com:2322 |

    ---
    ■ Synchronet ■ fatcats bbs - http://fatcats.poorcoding.com
  • From Tracker1@TRN to art on Wed Nov 18 04:56:47 2009
    On 11/18/2009 1:53 AM, art wrote:
    now you can use yourstring.ltrim()

    Thanks Deuce and Tracker1...

    I was hoping I wouldn't need to regexp it and it was provided as part of JSOM,
    however I'll likely implement a function as you guys have provided the regexp for, thanks.

    I have a pretty good set of ObjectModelExtensions for JS if you're interested.
    As it is, they should all work in synchronet. Most of them are for things that are sometimes surprising aren't *IN* JavaScript's language. Though it's pretty easy to extend/graft any object/class after the fact.

    I have stuff for some .toFormat overload methods for String and Date. I've also spent a little time trying to get base2 functioning in Synchronet properly, but that's been a bit of an effort. base.js works without much trouble though. Still need to implement a number formatter for String.toFormat. It does work with dates as-is ex:

    var fmt = "This is a string with a date-time of " +
    "{dtm:yyyy-MM-dd HH:mm:ss} " +
    "as well as another property of {prop2}.";
    var fmt2 = "This uses numbered arguments {0} and {1}";

    var now = new Date();
    var ret = fmt.toFormat({ dtm:now, prop2: 6 });
    var ret2 = fmt2.toFormat(now, 5);

    --
    Michael J. Ryan - http://tracker1.info/

    ... FRA #144: There's nothing wrong with charity ... as long as it winds up in your pocket.

    ---
    ■ Synchronet ■ Roughneck BBS - telnet://roughneckbbs.com - www.roughneckbbs.com
  • From art@FATCATS to Tracker1 on Wed Nov 18 13:41:45 2009
    Re: Re: truncsp() for beginnings of strings?
    By: Tracker1 to art on Wed Nov 18 2009 04:56:47

    I have a pretty good set of ObjectModelExtensions for JS if you're intereste
    As it is, they should all work in synchronet. Most of them are for things

    I would be interested in taking a look, if you're happy to provide it. Although the JS and Synchronet APIs are decent, some stuff like .trim would be very useful.

    Regards,
    Art at fatcats dot poorcoding dot com

    | fatcats bbs |
    | + telnet://fatcats.poorcoding.com |
    | + ssh://fatcats.poorcoding.com:2322 |

    ---
    ■ Synchronet ■ fatcats bbs - http://fatcats.poorcoding.com
  • From Deuce@SYNCNIX to Tracker1 on Wed Nov 18 09:29:46 2009
    Re: Re: truncsp() for beginnings of strings?
    By: Tracker1 to art on Tue Nov 17 2009 10:19 pm

    return this.replace(/^[\s\r\n]+/g, '');

    \s includes \r and \n. The g flag is useless since + is greedy by default and the match is anchored to the start of the string (unless you want multilines, which you don't).

    So just replace(/^\s+/, '');

    As for the whole string trim function...

    return this.replace(/^[\s\r\n]+|[\s\r\n]+$/g, '');

    replace(/^\s*(.*?)\s*$/, '$1');

    Is a lot better (a single replace, no OR, etc).

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From Deuce@SYNCNIX to art on Wed Nov 18 09:33:17 2009
    Re: Re: truncsp() for beginnings of strings?
    By: art to Tracker1 on Wed Nov 18 2009 08:53 am

    I was hoping I wouldn't need to regexp it and it was provided as part of JSOM, however I'll likely implement a function as you guys have provided
    the regexp for, thanks.

    Well, you could do it without a regexp, but it would be harder.

    ---
    Synchronet - Jump on the Web 0.2 bandwagon!

    ---
    ■ Synchronet ■ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From MCMLXXIX@MDJ to Deuce on Wed Nov 18 13:54:06 2009
    Re: Re: truncsp() for beginnings of strings?
    By: Deuce to art on Wed Nov 18 2009 09:33:17

    I was hoping I wouldn't need to regexp it and it was provided as part of JSOM, however I'll likely implement a function as you guys have provided the regexp for, thanks.

    Well, you could do it without a regexp, but it would be harder.


    you mean like my stupid function in funclib.js? yesssss

    ---
    ■ Synchronet ■ The BRoKEN BuBBLE (MDJ.ATH.CX)
  • From art@FATCATS to Deuce on Thu Nov 19 08:36:46 2009
    Re: Re: truncsp() for beginnings of strings?
    By: Deuce to art on Wed Nov 18 2009 09:33:17

    Well, you could do it without a regexp, but it would be harder.

    Hey Deuce,

    ... well... regexps are horrid enough... to try to do a regexp without regexps... sounds painful!

    Thanks for the regexp pointers in previous reply.

    Regs,
    Art at fatcats dot poorcoding dot com

    | fatcats bbs |
    | + telnet://fatcats.poorcoding.com |
    | + ssh://fatcats.poorcoding.com:2322 |

    ---
    ■ Synchronet ■ fatcats bbs - http://fatcats.poorcoding.com
  • From Tracker1@TRN to art on Sun Nov 29 10:34:40 2009
    On 11/18/2009 6:41 AM, art wrote:
    I have a pretty good set of ObjectModelExtensions for JS if you're intereste >> As it is, they should all work in synchronet. Most of them are for things

    I would be interested in taking a look, if you're happy to provide it. Although
    the JS and Synchronet APIs are decent, some stuff like .trim would be very useful.

    http://www.roughneckbbs.com/download/ObjectModelExtensions.zip
    see last post.

    --
    Michael J. Ryan - http://tracker1.info/

    ---
    ■ Synchronet ■ Roughneck BBS - telnet://roughneckbbs.com - www.roughneckbbs.com