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

RE: [Clip] String Split

Expand Messages
  • 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 1 of 11 , Aug 1 7:09 AM
      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 2 of 11 , Aug 1 7:25 AM
        --- 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 3 of 11 , Aug 1 7:38 AM
          "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 4 of 11 , Aug 1 7:52 AM
            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 5 of 11 , Aug 5 10:01 AM
              "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.