• console.strlen(text) vs. strip_ctrl(text).length

    From Nightfox@DIGDIST to Digital Man on Sunday, January 04, 2015 09:39:02
    Hi DM,

    While working on one of my scripts, there are some places where I need to get the length of a string as it will appear on the screen. It seems there are two ways to do so - console.strlen(text) and strip_ctrl(text).length. While working on one of my JS scripts, I noticed I'm getting two different results from each of those ways of getting string length for one of my script's strings. Specifically, my string has a 4 special characters to represent arrows, which are counted by console.strlen(), but those special arrow characters seem to be removed by strip_ctrl(). The following image shows the text line output from my script with the 4 arrow characters (it's a help line showing some valid key commands): http://home.comcast.net/~nightfox/BBSStuff/helpLine.png

    The length returned by console.strlen() is 79, whereas the length returned by strip_ctrl(text).length is 75.

    The documentation says console.strlen() will exclude Ctrl-A codes, while strip_ctrl() removes control characters. It sounds like strip_ctrl() might be removing all control characters (not just Ctrl-A characters), is that correct? I was curious if what I'm seeing is the expected behavior.

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion BBS - digitaldistortionbbs.com
  • From Digital Man to Nightfox on Sunday, January 04, 2015 19:20:06
    Re: console.strlen(text) vs. strip_ctrl(text).length
    By: Nightfox to Digital Man on Sun Jan 04 2015 09:39 am

    Hi DM,

    While working on one of my scripts, there are some places where I need to get the length of a string as it will appear on the screen. It seems there are two ways to do so - console.strlen(text) and strip_ctrl(text).length. While working on one of my JS scripts, I noticed I'm getting two different results from each of those ways of getting string length for one of my script's strings. Specifically, my string has a 4 special characters to represent arrows, which are counted by console.strlen(), but those special arrow characters seem to be removed by strip_ctrl(). The following image shows the text line output from my script with the 4 arrow characters (it's a help line showing some valid key commands): http://home.comcast.net/~nightfox/BBSStuff/helpLine.png

    The length returned by console.strlen() is 79, whereas the length returned by strip_ctrl(text).length is 75.

    The documentation says console.strlen() will exclude Ctrl-A codes, while strip_ctrl() removes control characters. It sounds like strip_ctrl() might be removing all control characters (not just Ctrl-A characters), is that correct? I was curious if what I'm seeing is the expected behavior.

    Yes, strip_ctrl() removes all control characters (ASCII value less than 32) and all Ctrl-A code sequences.

    What's the ASCII value of these "4 special characters to represent arrows"?

    digital man

    Synchronet "Real Fact" #71:
    Synchronet CIOXTRN (created by Deuce) is a 32-bit replacement for DOORWAY. Norco, CA WX: 59.1°F, 32.0% humidity, 7 mph W wind, 0.00 inches rain/24hrs
  • From Nightfox@DIGDIST to Digital Man on Sunday, January 04, 2015 19:54:25
    Re: console.strlen(text) vs. strip_ctrl(text).length
    By: Digital Man to Nightfox on Sun Jan 04 2015 19:20:06

    Yes, strip_ctrl() removes all control characters (ASCII value less than 32) and all Ctrl-A code sequences.

    What's the ASCII value of these "4 special characters to represent arrows"?

    Makes sense. The ASCII values (in decimal) are 16, 17, 24, and 25.

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion BBS - digitaldistortionbbs.com
  • From Digital Man to Nightfox on Monday, January 05, 2015 17:01:28
    Re: console.strlen(text) vs. strip_ctrl(text).length
    By: Nightfox to Digital Man on Sun Jan 04 2015 07:54 pm

    Re: console.strlen(text) vs. strip_ctrl(text).length
    By: Digital Man to Nightfox on Sun Jan 04 2015 19:20:06

    Yes, strip_ctrl() removes all control characters (ASCII value less
    than 32) and all Ctrl-A code sequences.

    What's the ASCII value of these "4 special characters to represent arrows"?

    Makes sense. The ASCII values (in decimal) are 16, 17, 24, and 25.

    Yup, those are control character. You can't really rely on them being displayed
    as printable characters (aka 'glyphs') in the terminal. If you try different terminal programs, you'll likely see different/inconsistent results.

    digital man

    Synchronet "Real Fact" #69:
    Rob Swindell was interviewed for Jason Scott's BBS Documentary in July of 2002. Norco, CA WX: 71.8°F, 18.0% humidity, 7 mph W wind, 0.00 inches rain/24hrs
  • From Nightfox@DIGDIST to Digital Man on Monday, January 05, 2015 19:55:16
    Re: console.strlen(text) vs. strip_ctrl(text).length
    By: Digital Man to Nightfox on Mon Jan 05 2015 17:01:28

    Makes sense. The ASCII values (in decimal) are 16, 17, 24, and 25.

    Yup, those are control character. You can't really rely on them being displayed as printable characters (aka 'glyphs') in the terminal. If you try different terminal programs, you'll likely see different/inconsistent results.

    I see. I'll have to give that a try.

    Nightfox

    ---
    ■ Synchronet ■ Digital Distortion BBS - digitaldistortionbbs.com