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

odd behavior in ^$StrAlign("Str";TextWidth;Alignment[;Pad=False])$ (added in v4.9)

Expand Messages
  • Don
    ^$StrAlign( Str ;TextWidth;Alignment[;Pad=False])$ (added in v4.9) ^!Replace ^( d+) ^$StrAlign( $1 ;5;Right)$ RAWS d is variable length ... seems
    Message 1 of 10 , Jul 7 12:59 AM
      ^$StrAlign("Str";TextWidth;Alignment[;Pad=False])$ (added in v4.9)

      ^!Replace "^(\d+) " >> "^$StrAlign("$1";5;Right)$ " RAWS

      \d is variable length ... seems that it treats everything as being the
      width of the narrowest encountered item ...

      I would have expected it to be variable width ... so that all items are
      then 5 characters wide, but in fact anything wider than the narrowest is
      over that by the extra digits greater than the narrower number I believe.

      1 data
      12 data
      234 data
      2 data


      1 data
      12 data
      234 data
      2 data

      Or maybe that isn't even it ... seems to always treat the number as
      being two in width, I think.
    • diodeom
      ... Or, as an alternative to looping, in two swaps: ^!Replace ^(?= d+) x20 x20 x20 x20 WARS ^!Replace ^ x20+?(.{4} d b) $1 WARS
      Message 2 of 10 , Jul 7 5:12 AM
        Flo wrote:
        >
        > What you are probably trying to achieve could be done if you replace that RegEx token with another string function (e.g. ^$GetSelection$)...
        >

        Or, as an alternative to looping, in two swaps:

        ^!Replace "^(?=\d+)" >> "\x20\x20\x20\x20" WARS
        ^!Replace "^\x20+?(.{4}\d\b)" >> "$1" WARS
      • Eb
        Don, NoteTab will parse the StrAling function only once, before it ever gets to the regular expression. Which means, it parses $1 as a literal dollar sign
        Message 3 of 10 , Jul 7 11:16 AM
          Don,


          NoteTab will parse the StrAling function only once, before it ever gets to the regular expression. Which means, it parses "$1" as a literal dollar sign followed by the numeral 1. A two character wide string.

          See the Parsing sequence in the Introduction to Clip Code Help.



          If you're looking for a way to line stuff up evenly, there was a post here not too long ago (by diodeom) showing how to justify numerals.

          You might search the posts for "sorting numbers" or variations of that phrase.


          Cheers,


          Eb


          --- In ntb-clips@yahoogroups.com, Don <don@...> wrote:
          >
          > ^$StrAlign("Str";TextWidth;Alignment[;Pad=False])$ (added in v4.9)
          >
          > ^!Replace "^(\d+) " >> "^$StrAlign("$1";5;Right)$ " RAWS
          >
          > \d is variable length ... seems that it treats everything as being the
          > width of the narrowest encountered item ...
          >
          > I would have expected it to be variable width ... so that all items are
          > then 5 characters wide, but in fact anything wider than the narrowest is
          > over that by the extra digits greater than the narrower number I believe.
          >
          > 1 data
          > 12 data
          > 234 data
          > 2 data
          >
          >
          > 1 data
          > 12 data
          > 234 data
          > 2 data
          >
          > Or maybe that isn't even it ... seems to always treat the number as
          > being two in width, I think.
          >
        • Don
          Now that makes perfect sense Eb. I get it now. I have either one, two or three digit numbers and need them all to be left padded. I just do two regexes in a
          Message 4 of 10 , Jul 7 2:13 PM
            Now that makes perfect sense Eb. I get it now.

            I have either one, two or three digit numbers and need them all to be
            left padded.

            I just do two regexes in a row and I have it. I had some other strings
            coming later that I insert one space at a time until get to the column I
            want. I was really angling for that use in the later spot. I can do it
            with a calc I suppose.

            On 7/7/2011 2:16 PM, Eb wrote:
            > Don,
            >
            >
            > NoteTab will parse the StrAling function only once, before it ever gets to the regular expression. Which means, it parses "$1" as a literal dollar sign followed by the numeral 1. A two character wide string.
            >
            > See the Parsing sequence in the Introduction to Clip Code Help.
            >
            >
            >
            > If you're looking for a way to line stuff up evenly, there was a post here not too long ago (by diodeom) showing how to justify numerals.
            >
            > You might search the posts for "sorting numbers" or variations of that phrase.
            >
            >
            > Cheers,
            >
            >
            > Eb
          • Eb
            Don, I found the message I mentioned (#21250). The part you ll be interested in is how Diodeom padded a set of numbers with the maximum width of zeros (I
            Message 5 of 10 , Jul 7 3:31 PM
              Don,

              I found the message I mentioned (#21250).

              The part you'll be interested in is how Diodeom padded a set of numbers with the maximum width of zeros (I suspect you could substitute spaces), then searches again, truncating the found numbers to the desired width.

              Cheers


              Eb


              --- In ntb-clips@yahoogroups.com, Don <don@...> wrote:
              >
              > Now that makes perfect sense Eb. I get it now.
              >
              > I have either one, two or three digit numbers and need them all to be
              > left padded.
              >
              > I just do two regexes in a row and I have it. I had some other strings
              > coming later that I insert one space at a time until get to the column I
              > want. I was really angling for that use in the later spot. I can do it
              > with a calc I suppose.
              >
              > On 7/7/2011 2:16 PM, Eb wrote:
              > > Don,
              > >
              > >
              > > NoteTab will parse the StrAling function only once, before it ever gets to the regular expression. Which means, it parses "$1" as a literal dollar sign followed by the numeral 1. A two character wide string.
              > >
              > > See the Parsing sequence in the Introduction to Clip Code Help.
              > >
              > >
              > >
              > > If you're looking for a way to line stuff up evenly, there was a post here not too long ago (by diodeom) showing how to justify numerals.
              > >
              > > You might search the posts for "sorting numbers" or variations of that phrase.
              > >
              > >
              > > Cheers,
              > >
              > >
              > > Eb
              >
            • diodeom
              ... To follow Don s outline indicated in ^$StrAlign( $1 ;5;Right)$ maybe something like: ^!Replace ^(?= d+) x20 x20 x20 x20 WARS ^!Replace
              Message 6 of 10 , Jul 7 7:31 PM
                --- In ntb-clips@yahoogroups.com, "Eb" <ebbtidalflats@...> wrote:
                >
                > padded a set of numbers with the maximum width of zeros (I suspect you could substitute spaces), then searches again, truncating the found numbers to the desired width.
                >

                To follow Don's outline indicated in "^$StrAlign("$1";5;Right)$" maybe something like:

                ^!Replace "^(?=\d+)" >> "\x20\x20\x20\x20" WARS
                ^!Replace "^\x20+?(.{4}\d\b)" >> "$1" WARS

                (Spaces represented in hex for clarity)
              • flo.gehrke
                ... Hi all, In the last days, my messages to the group appear topsy-turvy. Some arrive in the group, some get lost, some are returned to me and arrive in the
                Message 7 of 10 , Jul 8 5:54 AM
                  --- In ntb-clips@yahoogroups.com, "Eb" <ebbtidalflats@...> wrote:
                  >
                  > Don,
                  >
                  > NoteTab will parse the StrAling function only once...

                  Hi all,

                  In the last days, my messages to the group appear topsy-turvy. Some arrive in the group, some get lost, some are returned to me and arrive in the group one day after posting etc. I apologize for that inconvenience! -- Yahoo or my provider seems to get confused by anything -- maybe the Women's Soccer World Cup ;-)

                  Now, back to our topic! Eb wrote...

                  > NoteTab will parse the StrAling function only once, before it
                  > ever gets to the regular expression. Which means, it parses
                  > "$1" as a literal dollar sign followed by the numeral 1. A two
                  > character wide string.

                  Eb, I've got some problems with that explanation. Let's look at...

                  ^!Replace "^(\d+) " >> "^$StrAlign("$1";5;Right)$ " RAWS

                  again. Assuming that '$1' represents just a literal '$1' -- why doesn't this clip change the list...

                  1 data
                  12 data
                  234 data
                  2 data

                  to...

                  ···$1 data
                  ···$1 data
                  ···$1 data
                  ···$1 data

                  On the other hand, if we look at...

                  ^!Replace "^(\d+)" >> "^$StrCopy("$1";1;4)$ plus" WARS

                  this clip will change the list to...

                  1 plus data
                  12 plus data
                  234 plus data
                  2 plus data

                  That is, what is matched with the RegEx '^(\d+)' seems to get stored in '$1' and gets properly inserted with ^$StrCopy$ as part of the replacement string.

                  It has always confused me how NT is dealing with RegEx in string functions. I can't see a rule behind this. Could you comment on this problem one more time?

                  Thanks,
                  Flo
                • Don
                  ... Hi Flo, I think the answer is that it does exactly that .... it treats the $1 as TWO characters because at the time the string function executes it is
                  Message 8 of 10 , Jul 8 6:29 AM
                    > Eb, I've got some problems with that explanation. Let's look at...
                    >
                    > ^!Replace "^(\d+) " >> "^$StrAlign("$1";5;Right)$ " RAWS
                    >
                    > again. Assuming that '$1' represents just a literal '$1' -- why doesn't this clip change the list...
                    >
                    > 1 data
                    > 12 data
                    > 234 data
                    > 2 data
                    >
                    > to...
                    >
                    > ···$1 data
                    > ···$1 data
                    > ···$1 data
                    > ···$1 data

                    Hi Flo, I think the answer is that it does exactly that .... it treats
                    the $1 as TWO characters because at the time the string function
                    executes it is just that two characters.

                    So we get this:
                    ...$1 data
                    ...$1 data
                    ...$1 data
                    ...$1 data

                    It then does the "substitution" via regEx inserting a one digit number
                    instead of two in lines one and four and a three instead of two in line
                    three.
                    1 data
                    12 data
                    234 data
                    2 data

                    So the only one that is actually five characters in the end is line two
                    because we swap two characters (12) for two characters ($1).

                    In reality, I just do this in my current clip:
                    ;one digit
                    ^!Replace "^(\d) " >> " $1 " RAWS
                    ;two-digits
                    ^!Replace "^(\d\d) " >> " $1 " RAWS

                    Because I know the number of characters it is easy with these two
                    replaces, so the whole padding thing doesn't need to be done here.

                    Where I REALLY wanted to use this was later in my clip ... currently I
                    run this:
                    :GradeColumn
                    ^!If "^$GetCol$" > "^%theCol%" deleteOneGrade
                    ^!If "^$GetCol$" < "^%theCol%" addOneGrade
                    ^!If "^$GetLine$" = "^$GetLineCount$" TeamLoopStart

                    :GradeNextLine
                    ^!Jump +1
                    ^!Goto GradeLoop


                    :deleteOneGrade
                    ^!Select -1
                    ^!InsertText ^%EMPTY%
                    ^!Goto GradeColumn


                    :addOneGrade
                    ^!InsertText ^%SPACE%
                    ^!Goto GradeColumn

                    What it does is place the cursor before data in the middle of a line,
                    calculate what column I am in, and then essentially add spaces until I
                    am in the desired column (or subtract if I am too long). Note that to
                    avoid delay issues inherent in keyboard commands, that instead of
                    Keyboard+Space I use inserttext. When I originally tried keyboard
                    commands the machine would periodically hang mid clip -- I am running
                    this on hundreds of lines and I might be inserting 0-20 spaces in each
                    of the lines.

                    I am debating if I should instead be simply doing math ... calc desired
                    column - actual column = number of spaces to pad, then use insert text
                    with ^$StrFill("Str";Amount)$




                    and then it NEXT does the replace so that $1 gets replaced with the
                    proper number which may be more or less than the two characters used by $1

                    So
                    ...x data
                    ...12 data
                  • Eb
                    Hi Flo, Don has already answered your question. But let me put my own spin on it. When NoteTab parses the function which takes its input ( $1 ) and modifies it
                    Message 9 of 10 , Jul 8 10:07 AM
                      Hi Flo,

                      Don has already answered your question. But let me put my own spin on it.

                      When NoteTab parses the function which takes its input ("$1") and modifies it by adding spaces. In other words, the function passes the literal string '$1' through, along with the additional spaces.

                      So the regular expression sees the output of the function:

                      " $1 "

                      which is a perfect pattern, into which to insert each group content.

                      i.e. (used monospaced text to align the before and after):


                      " $1 " becomes:
                      " 234 data "


                      Your example with StrCopy works exactly the same way. StrCopy copies up to the 4 characters you told it to copy, and passes them to the regular expression. Since the string contains only "$1" it passes that out to the regexp engine, which sees it as a replacement token.


                      (1) --> "$1 plus" --> "1 plus"
                      (12) --> "$1 plus" --> "12 plus"
                      (234)--> "$1 plus" --> "234 plus"

                      One more thing. Suppose the str function is in the search pattern. It too will only get parsed once, and the result passed to the regexp engine. However, most of the time you will probably not have a group passed into the function to confuse the issue.
                      Though you could (using \1).


                      Cheers,


                      Eb

                      --- In ntb-clips@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
                      >
                      ...
                      > > NoteTab will parse the StrAling function only once...

                      the dingaling wrote stringaling

                      >
                      > Eb, I've got some problems with that explanation. Let's look at...
                      >
                      > ^!Replace "^(\d+) " >> "^$StrAlign("$1";5;Right)$ " RAWS

                      ...

                      > On the other hand, if we look at...
                      >
                      > ^!Replace "^(\d+)" >> "^$StrCopy("$1";1;4)$ plus" WARS
                      >
                    • flo.gehrke
                      ... Don & Eb, Thanks for your replies! Now the penny has dropped for me. My point was that I was confused by Eb s statement... ... I misunderstood this
                      Message 10 of 10 , Jul 9 3:48 AM
                        --- In ntb-clips@yahoogroups.com, "Eb" <ebbtidalflats@...> wrote:
                        >
                        > Hi Flo,
                        >
                        > Don has already answered your question. But let me put my own spin on it...

                        Don & Eb,

                        Thanks for your replies!

                        Now the penny has dropped for me. My point was that I was confused by Eb's statement...

                        > (NT) parses "$1" as a literal dollar sign followed by the numeral 1.
                        > A two character wide string.

                        I misunderstood this sentence as if '$1' would loose its capability to work as a kind of variable. That is, it would have the same effect as writing...

                        ^!Replace "^(\d+)" >> "^$StrAlign("XY";5;Right)$" RAWS

                        which would end up with...

                        ...XY data
                        ...XY data
                        ...XY data
                        ...XY data

                        without inserting any numbers. As a consequence of this misunderstanding I wondered: "Where do the numbers come from if it's only a string?".

                        Thanks to your explanations it's clear now!

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