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

Hello (Reg. Exp. Find and Replace, coding question)!

Expand Messages
  • copyacademyperfect
    This is a nOOb warning, going out first. Just so you know; in case the question is really dumb - maybe I should explain... I ve been coding for twelve hours,
    Message 1 of 3 , Apr 13, 2008
    • 0 Attachment
      This is a nOOb warning, going out first. Just so you know; in case the
      question is really dumb - maybe I should explain... I've been coding
      for twelve hours, or so, and It wasn't on purpose. I got stuck with
      this batch rename .txt-file I wanted to make, but I can't solve the
      final detail.

      So I beg all nice ladies (how big is the chance?) and gentlemen...
      please help me out (it's not a matter of life and death, unless lack of
      satisfied curiousity is gonna kill me soon).

      BATCHRENAME.txt

      First Line:

      BLACK_FRAMECAPTIONMIN_BMP BITMAP "Bitmap_20.bmp"

      //the file consists of several lines that look somewhat like this, and
      they can be divided into left and right parts. I want to move the right
      part of the line to the left side with text modifications to both parts.

      This is how I coded (one of the versions) the first line's match
      field://

      (BLACK_)(.+)(_BMP) BITMAP "Bitmap_(\d{3}|\d{2})(.bmp)"

      //...with the quotes. This code find the various lines in the document
      (havent tested all, but I see no reason why it shouldn't work).

      I changed the second word to "(.+)" because it changes every line. I
      also added "\d{3}" as an alternative since the number (HERE=20) will
      increase above "100" in just eighty lines.

      There's more than one reason why I'm using substring tokens where it's
      not really necessary, which leads me to chat about the "replace field."
      This is how I want the first line replaced://

      BLACK_0020_BMP.bmp=BLACK_FRAMECAPTIONMIN_BMP.bmp

      //This is how it turned out and how I coded://

      BLACK_20_BMP.bmp=BLACK_FRAMECAPTIONMIN_BMP.bmp

      $1$4$3$5=$1$2$3$5

      //I am having difficulties with the digit(s) that is/are supposed to
      initiate the second word. Sure I could just: $1\0\0$4$3$5=$1$2$3$5,
      insert them there, but sooner or later the second word will reach above
      100 and then there will be five digits in the second word://

      BLACK_00101_BMP.bmp=BLACK_TABITEM_BMP.bmp

      //

      I have tried everything I've learned during these 18 hours or so, but I
      can not solve it. How do I enforce maximum four digits (add only one
      zero if above 99, instead of two) on the second word?

      The practical solution is so simple. I'd just run the first 80 lines
      adding two digits, and then the rest adding one. But I'd really wanna
      know if there's a way?

      Thanks for reading.
      /Peter
    • Don - HtmlFixIt.com
      Some padding things in notetab: Choice one (probably not): ^!SetNameFormat Mask (added in v4.6) The name format is used when new documents are created. The
      Message 2 of 3 , Apr 13, 2008
      • 0 Attachment
        Some padding things in notetab:

        Choice one (probably not):
        ^!SetNameFormat Mask (added in v4.6)
        The name format is used when new documents are created. The code "%d"
        indicates where the incremental numbering is inserted in the name. In
        the following example, the "0.2" between the % and d tells NoteTab to
        format numbers smaller than 2 digits with leading zeroes: NoName%0.2d.txt


        Padding on a string (probably not, limited to spaces -- would be great
        if you could specify the padding character):
        ^$StrAlign("Str";TextWidth;Alignment[;Pad=False])$ (added in v4.9)

        This function aligns the Str value within a space specified by
        TextWidth. Alignment values can be Left, Right, or Center. If the Pad
        parameter is used, a True value adds blank spaces on the right side of
        Str (if necessary). Examples:

        ^$StrAlign("Test";10;Right)$ -> " Test"

        ^$StrAlign("Test";10;Center;True)$ -> " Test "

        Of course you could do a second replace I suppose.

        I often use this routine to zero pad things:
        ;use Hugo's ideas to get places and pad with zeros
        ^!Set %Field%=^$GetField(^$GetRow$;1)$
        ^!If ^$StrSize("^%Field%")$=1 ^!Set %Field%=00^%Field%
        ^!If ^$StrSize("^%Field%")$=2 ^!Set %Field%=0^%Field%

        But that assumes that you have created a variable.

        There is a way to assign the regex find patterns to a variable and then
        you can work on it.

        Are you doing this with a clip?

        Here is another zero padding method I have used:
        ^!Set %format%="^$GetLineCount$"
        ^!Set %formatsize%="^$StrSize("^%format%")$"


        :Loop
        ^!Jump Line_End
        ; set padding of zero's
        ^!Set %length%="^$Calc(^%formatsize%-^$StrSize("^$GetRow$")$)$"
        ^!InsertText ^$StrFill(0;^%length%)$^%Line%

        I have spent half of my life doing zero padding.
      • copyacademyperfect
        ... Thank You! I ll try your Jedi mind tricks, one by one. I am so very green I hafta read everything four, five or six times while focusing on some manual in
        Message 3 of 3 , Apr 14, 2008
        • 0 Attachment
          --- In ntb-scripts@yahoogroups.com, "Don - HtmlFixIt.com" <don@...>
          wrote:

          > Some padding things in notetab:

          Thank You! I'll try your Jedi mind tricks, one by one. I am so very
          green I hafta read everything four, five or six times while focusing on
          some manual in another window while jotting down the code. If I only
          had known/explored the ^!if and ^!set commands (for example) last night.


          > Are you doing this with a clip?

          I have recently (four days?) started to use NoteTab. I've only
          searched/replaced files all days now. I have also discovered NoteTab's
          excellent ways of fixing and dealing with lines. But from what I
          understand, "clipping" is something I'll play with quite abit.


          > I have spent half of my life doing zero padding.

          I've spent more than half of my life (=24/33years) using computers
          doing "zero coding" (=not any at all). Why? You can really utilize your
          machine with it, and do all those little things you wish was
          implemented in various software. Suddenly I am issuing commands from
          one application into another in commandlines without opening any
          window. This is great when you're working with pictures/audio, like I
          do. Thank You NoteTab!

          And thanks Don. 'tis really nice of you to take the time. Appriciate it.

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