• truncsp() for beginnings of strings?

    From art@VERT/FATCATS to All on Tue Nov 17 17: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@VERT/SYNCNIX to art on Tue Nov 17 17: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@VERT/TRN to art on Wed Nov 18 06: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@VERT/FATCATS to Tracker1 on Wed Nov 18 16: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@VERT/TRN to art on Wed Nov 18 12: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@VERT/FATCATS to Tracker1 on Wed Nov 18 21: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@VERT/SYNCNIX to Tracker1 on Wed Nov 18 17: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@VERT/SYNCNIX to art on Wed Nov 18 17: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@VERT/MDJ to Deuce on Wed Nov 18 21: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@VERT/FATCATS to Deuce on Thu Nov 19 16: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@VERT/TRN to art on Sun Nov 29 18: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