Loading ...
Sorry, an error occurred while loading the content.

String Split

Expand Messages
  • Axel Berger
    With the command ^!InsertText ^$StrSplit( ^$GetSelection$ ;70;FALSE)$ I had expected every line to end with a space before the return. Isn t that what the
    Message 1 of 11 , Aug 1, 2008
    • 0 Attachment
      With the command

      ^!InsertText ^$StrSplit("^$GetSelection$";70;FALSE)$

      I had expected every line to end with a space before the return.
      Isn't that what the FALSE stands for? Not so, no space. What's
      wrong?

      Axel
    • Don - HtmlFixIt.com
      ... This simply means IF there is a space at the end of the line (or spaces) should they be trimmed or not. It does not insert a space for you. Assuming I
      Message 2 of 11 , Aug 1, 2008
      • 0 Attachment
        Axel Berger wrote:
        > With the command
        >
        > ^!InsertText ^$StrSplit("^$GetSelection$";70;FALSE)$
        >
        > I had expected every line to end with a space before the return.
        > Isn't that what the FALSE stands for? Not so, no space. What's
        > wrong?
        >
        > Axel

        This simply means IF there is a space at the end of the line (or spaces)
        should they be trimmed or not. It does not insert a space for you.
        Assuming I understand your question right anyway you expected it to
        insert a space at the end of each line? Trim to 69 and insert a space
        at 70 if you wish.

        See if this is what you wanted?

        ^!InsertText ^$StrSplit("^$GetSelection$";69;FALSE)$^%SPACE%


        ^%SPACE% = Blank space character of course

        You may get multiple spaces at the end of course.
      • John Shotsky
        It can also be done throughout a document with a Replace command, such as: ^!Replace (.+) s? R $1^%SPACE%^%NL% ARSTW This will replace any existing
        Message 3 of 11 , Aug 1, 2008
        • 0 Attachment
          It can also be done throughout a document with a Replace command, such as:
          ^!Replace "(.+)\s?\R" >> "$1^%SPACE%^%NL%" ARSTW

          This will replace any existing spaces with a single space, or add a space if there is not one present. It will not place
          a space in a blank line.

          John

          From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Don - HtmlFixIt.com
          Sent: Friday, August 01, 2008 5:50 AM
          To: ntb-clips@yahoogroups.com
          Subject: Re: [Clip] String Split

          Axel Berger wrote:
          > With the command
          >
          > ^!InsertText ^$StrSplit("^$GetSelection$";70;FALSE)$
          >
          > I had expected every line to end with a space before the return.
          > Isn't that what the FALSE stands for? Not so, no space. What's
          > wrong?
          >
          > Axel

          This simply means IF there is a space at the end of the line (or spaces)
          should they be trimmed or not. It does not insert a space for you.
          Assuming I understand your question right anyway you expected it to
          insert a space at the end of each line? Trim to 69 and insert a space
          at 70 if you wish.

          See if this is what you wanted?

          ^!InsertText ^$StrSplit("^$GetSelection$";69;FALSE)$^%SPACE%

          ^%SPACE% = Blank space character of course

          You may get multiple spaces at the end of course.



          [Non-text portions of this message have been removed]
        • Don - HtmlFixIt.com
          ... Wow, much as I don t understand it, I love regex! What power! Okay so .+ means one or more of any character(s) except a new line. That is matched and put
          Message 4 of 11 , Aug 1, 2008
          • 0 Attachment
            John Shotsky wrote:
            > It can also be done throughout a document with a Replace command, such as:
            > ^!Replace "(.+)\s?\R" >> "$1^%SPACE%^%NL%" ARSTW
            >
            > This will replace any existing spaces with a single space, or add a space if there is not one present. It will not place
            > a space in a blank line.
            >
            > John

            Wow, much as I don't understand it, I love regex! What power!

            Okay so .+ means one or more of any character(s) except a new line.
            That is matched and put into a match string that can be referred to as
            $1 because it is contained in parenthesis, so on the back side, $1
            reinserts that.

            \s means white space, so a space before an \R (meaning a return
            character -- I'm still in the habit of using \r\n instead I think ...)
            and the ? means zero or one, so the space is optional, but if no space,
            no problem and if space, it is left our of the $1 match string.

            Of course the back side is reinsert everything but the trailing space,
            add a space to each line and add a new line.

            However, he was trimming to 70 characters, won't this make variable
            length lines that may be either 71 (if no space) or 70 is space because
            you trim and then reinsert a space?

            I am not seeing how this eliminates existing spaces (as in multiples) if
            that was what you meant by replacing existing spaces, or did you mean
            one per line at the end?

            Thanks for the exercise as these really help me John,

            Don
          • Axel Berger
            ... Well, that space is already there. My selection contains a line of several hundred bytes length. What StrSplit does is go to 70 and then go backward to the
            Message 5 of 11 , Aug 1, 2008
            • 0 Attachment
              "Don - HtmlFixIt.com" wrote:
              > This simply means IF there is a space at the end of the line
              > (or spaces) should they be trimmed or not. It does not insert
              > a space for you.

              Well, that space is already there. My selection contains a line of
              several hundred bytes length. What StrSplit does is go to 70 and
              then go backward to the next space and split the line there. (Or
              something very similar, this is how I did it in BASIC many years
              ago.) So my one line becomes many and at every new line-end there
              was a space originally.

              NB: Your suggestion will only add a single space after the last of
              the lines. In my full version I put an extra newline there.

              My text contains blocks pasted into it with very long or very short
              lines. I add empty lines between paragraphs I want to keep as such,
              find those blocks and do:

              ; Remember empty lines
              ^!InsertSelect
              ^$StrReplace("^P^P";"^T^T";"^$GetSelection$";FALSE;FALSE)$
              ; Make paragraphs one line
              ^!InsertSelect ^$StrReplace("^P";" ";"^$GetSelection$";FALSE;FALSE)$
              ; Make remembered markers line ends
              ^!InsertSelect
              ^$StrReplace("^T^T";"^P";"^$GetSelection$";FALSE;FALSE)$
              ; Split long lines to desired length
              ^!InsertText ^$StrSplit("^$GetSelection$";70;FALSE)$^P
              ; Find next instance
              ^!Goto loop

              Obviously the last FALSE means something else than I expect it to.

              Axel
            • Don - HtmlFixIt.com
              Okay, I tested this now on some text. If I use FALSE at the end, all lines are hard wrapped/split at 70 or less and there is a trailing space on the line ...
              Message 6 of 11 , Aug 1, 2008
              • 0 Attachment
                Okay, I tested this now on some text.

                If I use FALSE at the end, all lines are hard wrapped/split at 70 or
                less and there is a trailing space on the line ... if it is wrapped.
                FALSE stops it from removing the trailing space that caused the split,
                in other words.

                Lines that end short of 70 do not have a space inserted after them
                because they were the natural ends and aren't wrapped by the function.

                If I use TRUE at the end of the function, then all lines are hard
                wrapped at 70 or less, but there is no trailing space. This makes it
                remove the delimiting space at the end of each line as it wraps.

                It seems to work as I would expect.

                Test Block:
                ^$StrEncrypt("Text";[Key])$ (added in v4.84)

                Provides stronger text encryption than ROT13. Use the optional "Key"
                parameter to define an encryption password (maximum 255 characters and
                case sensitive). Make sure you don't forget the key you used with this
                function, otherwise you may never be able to retrieve your encrypted
                text. Note that although the encryption algorithm is very good, there is
                no guarantee that it can't be cracked. You should not rely on it to
                protect very sensitive data. Example:

                ^$StrEncrypt("^$GetSelection$";"^?[key=My secret password]")$



                ^$StrFill("Str";Amount)$

                Returns a string entirely composed of the defined character or text
                repeated Amount times. Examples:

                ^$StrFill(+;4)$ -> ++++

                ^$StrFill("<>";4)$ -> <><><><>



                ^$StrFixLines("Str")$ (added in v4.51)

                Corrects carriage returns in text criteria (Unix and Mac-formatted text
                is converted to Dos/Windows format).



                ^$StrFormat("Str";LeftMargin;TextWidth;Justify)$

                Returns the "Str" string in specified format. LeftMargin determines the
                number of blank spaces to insert between the left margin and the text;
                TextWidth defines the maximum width of the text in each line; Justify is
                either True or False and determines if the text is left and right
                justified. Prior to version 4.8, this command was only available in the
                commercial and trial versions of NoteTab.


                With FALSE (set to 20 instead of 70 to make it easier and avoid wrap in
                email and replacing spaces with # to make it easier to see):
                ^$StrEncrypt("Text"
                ;[Key])$#(added#in#
                v4.84)

                Provides#stronger#
                text#encryption#than#
                ROT13.#Use#the#
                optional#"Key"#
                parameter#to#define#
                an#encryption#
                password#(maximum#
                255#characters#and#
                case#sensitive).#
                Make#sure#you#don't#
                forget#the#key#you#
                used#with#this#
                function,#otherwise#
                you#may#never#be#
                able#to#retrieve#
                your#encrypted#text.#
                Note#that#although#
                the#encryption#
                algorithm#is#very#
                good,#there#is#no#
                guarantee#that#it#
                can't#be#cracked.#
                You#should#not#rely#
                on#it#to#protect#
                very#sensitive#data.#
                Example:

                ##
                ^$StrEncrypt("
                ^$GetSelection$";"^
                ?[key=My#secret#
                password]")$

                #

                ^$StrFill("Str"
                ;Amount)$

                Returns#a#string#
                entirely#composed#of#
                the#defined#
                character#or#text#
                repeated#Amount#
                times.#Examples:

                ^$StrFill(+;4)$##->##
                ++++

                ^$StrFill("<>";4)$##
                ->##<><><><>

                #

                ^$StrFixLines("Str"
                )$#(added#in#v4.51)

                Corrects#carriage#
                returns#in#text#
                criteria#(Unix#and#
                Mac-formatted#text#
                is#converted#to#
                Dos/Windows#format).

                #

                ^$StrFormat("Str"
                ;LeftMargin
                ;TextWidth;Justify)$

                Returns#the#"Str"#
                string#in#specified#
                format.#LeftMargin#
                determines#the#
                number#of#blank#
                spaces#to#insert#
                between#the#left#
                margin#and#the#text;#
                TextWidth#defines#
                the#maximum#width#of#
                the#text#in#each#
                line;#Justify#is#
                either#True#or#False#
                and#determines#if#
                the#text#is#left#and#
                right#justified.#
                Prior#to#version#
                4.8,#this#command#
                was#only#available#
                in#the#commercial#
                and#trial#versions#
                of#NoteTab.

                #

                So there is a space LEFT at the end of each line where the line was
                split if you do it with FALSE. There is not a line inserted if the
                remaining piece of the line does not need to be split or if the line was
                less than the character length to begin with.

                And with it set to TRUE you get no trailing space because it is removed
                as part of the wrapping:
                ^$StrEncrypt("Text"
                ;[Key])$#(added#in
                v4.84)

                Provides#stronger
                text#encryption#than
                ROT13.#Use#the
                optional#"Key"
                parameter#to#define
                an#encryption
                password#(maximum
                255#characters#and
                case#sensitive).
                Make#sure#you#don't
                forget#the#key#you
                used#with#this
                function,#otherwise
                you#may#never#be
                able#to#retrieve
                your#encrypted#text.
                Note#that#although
                the#encryption
                algorithm#is#very
                good,#there#is#no
                guarantee#that#it
                can't#be#cracked.
                You#should#not#rely
                on#it#to#protect
                very#sensitive#data.
                Example:


                ^$StrEncrypt("
                ^$GetSelection$";"^
                ?[key=My#secret
                password]")$

                #

                ^$StrFill("Str"
                ;Amount)$

                Returns#a#string
                entirely#composed#of
                the#defined
                character#or#text
                repeated#Amount
                times.#Examples:

                ^$StrFill(+;4)$##->#
                ++++

                ^$StrFill("<>";4)$
                ->##<><><><>

                #

                ^$StrFixLines("Str"
                )$#(added#in#v4.51)

                Corrects#carriage
                returns#in#text
                criteria#(Unix#and
                Mac-formatted#text
                is#converted#to
                Dos/Windows#format).

                #

                ^$StrFormat("Str"
                ;LeftMargin
                ;TextWidth;Justify)$

                Returns#the#"Str"
                string#in#specified
                format.#LeftMargin
                determines#the
                number#of#blank
                spaces#to#insert
                between#the#left
                margin#and#the#text;
                TextWidth#defines
                the#maximum#width#of
                the#text#in#each
                line;#Justify#is
                either#True#or#False
                and#determines#if
                the#text#is#left#and
                right#justified.
                Prior#to#version
                4.8,#this#command
                was#only#available
                in#the#commercial
                and#trial#versions
                of#NoteTab.

                #


                Note that there are no trailing spaces on lines after the split.
              • John Shotsky
                Don, You have correctly interpreted the regex. I thought the lines were already split, and the goal was just to add the space at the end. At this point, it
                Message 7 of 11 , Aug 1, 2008
                • 0 Attachment
                  Don,

                  You have correctly interpreted the regex. I thought the lines were already split, and the goal was just to add the space
                  at the end.

                  At this point, it would be helpful to see a snippet of source with a clear explanation of what is needed. Regex can
                  probably do everything in one command.

                  \R means any line terminator, even a combination of CRLF. I use that in the find side, and use \n or ^%NL% in the
                  replace side.

                  You are right about the spaces - it would need to be \s* to capture zero or multiple spaces. I wrote it thinking there
                  might already be only one space.

                  John

                  From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Don - HtmlFixIt.com
                  Sent: Friday, August 01, 2008 6:31 AM
                  To: ntb-clips@yahoogroups.com
                  Subject: Re: [Clip] String Split

                  John Shotsky wrote:
                  > It can also be done throughout a document with a Replace command, such as:
                  > ^!Replace "(.+)\s?\R" >> "$1^%SPACE%^%NL%" ARSTW
                  >
                  > This will replace any existing spaces with a single space, or add a space if there is not one present. It will not
                  place
                  > a space in a blank line.
                  >
                  > John

                  Wow, much as I don't understand it, I love regex! What power!

                  Okay so .+ means one or more of any character(s) except a new line.
                  That is matched and put into a match string that can be referred to as
                  $1 because it is contained in parenthesis, so on the back side, $1
                  reinserts that.

                  \s means white space, so a space before an \R (meaning a return
                  character -- I'm still in the habit of using \r\n instead I think ...)
                  and the ? means zero or one, so the space is optional, but if no space,
                  no problem and if space, it is left our of the $1 match string.

                  Of course the back side is reinsert everything but the trailing space,
                  add a space to each line and add a new line.

                  However, he was trimming to 70 characters, won't this make variable
                  length lines that may be either 71 (if no space) or 70 is space because
                  you trim and then reinsert a space?

                  I am not seeing how this eliminates existing spaces (as in multiples) if
                  that was what you meant by replacing existing spaces, or did you mean
                  one per line at the end?

                  Thanks for the exercise as these really help me John,

                  Don



                  [Non-text portions of this message have been removed]
                • Sheri
                  ... I m not sure StrSplit is doing. I have View Nonprinting characters enabled. If I have a document with: abc followed by 70 spaces followed by abc followed
                  Message 8 of 11 , Aug 1, 2008
                  • 0 Attachment
                    --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
                    >
                    > With the command
                    >
                    > ^!InsertText ^$StrSplit("^$GetSelection$";70;FALSE)$
                    >
                    > I had expected every line to end with a space before the return.
                    > Isn't that what the FALSE stands for? Not so, no space. What's
                    > wrong?
                    >
                    > Axel
                    >

                    I'm not sure StrSplit is doing.

                    I have View Nonprinting characters enabled.

                    If I have a document with:

                    abc followed by 70 spaces followed by abc followed by three spaces

                    And I highlight that and run the above clip, it keeps all the spaces
                    and the two resulting lines both start with abc.

                    If I change the FALSE to TRUE, I get exactly the same result.

                    If I do the same thing in NTP version 4.95, with TRUE the trailing
                    spaces get removed and both lines have just abc on them.

                    So it would seem that the function's behavior changed at some point. I
                    am currently running NTP 5.7b.

                    Regards,
                    Sheri
                  • Axel Berger
                    ... That s what I expected to happen. Doesn t do so here. As it works for you, the mistake must be somewhere one my side. Danke Axel
                    Message 9 of 11 , Aug 1, 2008
                    • 0 Attachment
                      "Don - HtmlFixIt.com" wrote:
                      > Provides#stronger#
                      > text#encryption#than#
                      > ROT13.#Use#the#
                      > optional#"Key"#

                      That's what I expected to happen. Doesn't do so here. As it works
                      for you, the mistake must be somewhere one my side.

                      Danke
                      Axel
                    • Don - HtmlFixIt.com
                      ... I am apparently in 5.5. I have 5.7, but need to get it to start when I click on notetab. Perhaps the version number does have something to do with it. I
                      Message 10 of 11 , Aug 1, 2008
                      • 0 Attachment
                        Axel Berger wrote:
                        > "Don - HtmlFixIt.com" wrote:
                        >> Provides#stronger#
                        >> text#encryption#than#
                        >> ROT13.#Use#the#
                        >> optional#"Key"#
                        >
                        > That's what I expected to happen. Doesn't do so here. As it works
                        > for you, the mistake must be somewhere one my side.
                        >
                        > Danke
                        > Axel

                        I am apparently in 5.5. I have 5.7, but need to get it to start when I
                        click on notetab. Perhaps the version number does have something to do
                        with it.

                        I tried Sheri's example and got very odd results. If you have abc[bunch
                        of spaces]abc[spaces] it doesn't trim the spaces up to the width with
                        true, but does trim them after the width. With False, it doesn't trim
                        any spaces, so you are left with lines with spaces going out way past
                        the specified width!
                      • Axel Berger
                        ... Not quite. I have found my mistake here. I have got into the habit of writing a capital FALSE which usually works, but not in ^$StrSplit. This function
                        Message 11 of 11 , Aug 5, 2008
                        • 0 Attachment
                          "Don - HtmlFixIt.com" wrote:
                          > If I use FALSE at the end, all lines are hard wrapped/split at
                          > 70 or less and there is a trailing space on the line ... if it
                          > is wrapped. FALSE stops it from removing the trailing space
                          > that caused the split, in other words.

                          Not quite. I have found my mistake here. I have got into the habit
                          of writing a capital "FALSE" which usually works, but not in
                          ^$StrSplit. This function requires "False" exactly as in the help
                          file, so there's noone to blame but me.

                          Axel
                        Your message has been successfully submitted and would be delivered to recipients shortly.