Author Topic: How to match a number 'A' with number 'A' without know what number 'A' is ...  (Read 3621 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Huh, ...  confusing.
Lemme see if I can explain it a better way.

I have a bunch of job numbers in a directory.
Quote
...
06112
06113 -Horizon
06113.A -Horizon Addition
06113.A2 -Horizon Addition Revised
 ...

I need to match 06113.A2 with 06113.A2 without knowing whether or not it has a name after it and without knowing if it is 5 digits, 6 digits, 7 digits, or 8.

Code: [Select]
(setq CurrentFilePath (getvar "dwgprefix"))  ; returns X:\Drawings 2006\06113.A2 -Horizon Addition Revised\\
(setq CFJobNmbr (substr CurrentFilePath 18)) ; returns 06113.A2 -Horizon Addition Revised\\
(setq CFJobNmbr (substr CFJobNmbr 1 8)) ; returns 06113.A2
 ...  Now it gets tricky
If I am currently in 06113
Code: [Select]
(setq CurrentFilePath (getvar "dwgprefix"))  ; returns X:\Drawings 2006\06113 -Horizon\\
(setq CFJobNmbr (substr CurrentFilePath 18)) ; returns 06113 -Horizon\\
(setq CFJobNmbr (substr CFJobNmbr 1 8)) ; returns 06113 -H

If CFJobNmbr is 8 characters (06113.A2), then
Code: [Select]
(setq FilePathEnding CFJobNmbr)
If the job number is 06113, then I need only the 5 characters.  Otherwise I get 06113 -H for my return.

So my question is;
How can I extract the job number from the dwgprefix without the name after the job number & determine if I need 5 characters or 6, or 7, or 8 ??

I was looking at wcmatch, but I'm not sure how I would put that together to make it work yet.  Do you have any other suggestions ??

Thank you for your advice in advance,
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
I still don't know what you want.  Is there a space after? or a hyphen (-)?  If so then you can use thos as items to search for from the beginning of the string, then you will know the length of the string you are looking for.

Was that any help?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Yes Tim, there are both a space & a hyphen.  Depending on the job number.  Some job numbers are just that, 5 digit to 8 digit numbers.  Others have the 5 or 6 or 7 or 8 digit job number, a space, a hyphen, and the name of the job.

How can I make the search get just those 5 to 8 digits ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Use 'vl-string-search' with the first character, the space.  Then subtract one or two from that number, and then use 'substr' on the project name from the beginning to the number you got from subtracting one from what 'vl-search-string' returned.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Yes Tim, there are both a space & a hyphen.  Depending on the job number.  Some job numbers are just that, 5 digit to 8 digit numbers.  Others have the 5 or 6 or 7 or 8 digit job number, a space, a hyphen, and the name of the job.

How can I make the search get just those 5 to 8 digits ??

If all else fails try:
(atoi "06113 -H")
6113

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

SomeCallMeDave

  • Guest
Maybe something like this will work.  You will probably want to play with the match patterns since I wasn't sure of all your criteria.

Code: [Select]
(defun c:testJobName()
   (setq TestString (getString T "\nEnter Job Name: ")
         NameLength (JobNameLength TestString)
    )   

)

(defun JobNameLength(pJobName)

    (cond
       ((wcmatch pJobName "#####`.?# *")
          (setq NameLength 8)
       )
       ((wcmatch pJobName "#####`.? *")
          (setq NameLength 7)
       )   
       ((wcmatch pJobName "##### *")
          (setq NameLength 5)
       )
       ( T)
          (setq NameLength (strlen pJobName))
    );cond
   
   
    NameLength
       

)


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Code: [Select]
(SETQ folders '("06112"
                "06113 -Horizon"
                "06113.A -Horizon Addition"
                "06114.A2 -Horizon Addition Revised"
               )
)

(FOREACH folder folders
   (ALERT (VL-PRINC-TO-STRING (READ folder)))
)


Sorry, I missed the.A or the .A2 bit ..  thats next ..

needed to ask .. is there ALWAYS a space after your "number" "
« Last Edit: April 13, 2007, 07:48:03 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
if so ..
perhaps try something like this

Code: [Select]
(SETQ folders '("06112"
                "06113 -Horizon"
                "06113.A -Horizon Addition"
                "06114.A2 -Horizon Addition Revised"
               )
)

(FOREACH folder folders
   (IF (SETQ index (VL-STRING-POSITION (ASCII " ") folder))
      (ALERT (SUBSTR folder 1 index))
      (ALERT folder)
   )
)

This of course assumes your list is valid, which in this case it should be.
« Last Edit: April 13, 2007, 08:04:18 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10652
Yes Tim, there are both a space & a hyphen.  Depending on the job number.  Some job numbers are just that, 5 digit to 8 digit numbers.  Others have the 5 or 6 or 7 or 8 digit job number, a space, a hyphen, and the name of the job.

How can I make the search get just those 5 to 8 digits ??

If all else fails try:
(atoi "06113 -H")
6113

Gary
Very nice.

I was reading this post thinking to myself how i could loop-check-strip-whatever. Then as soon as i saw atoi in your post...Im gonna remember that one.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
unfortunately atoi has the same issue as read
... it drops any preceding zeros.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

VVA

  • Newt
  • Posts: 166
If I have correctly understood
Code: [Select]
;(str-str-lst "This is job" " ")
;Return ("This" "is" "job")

(defun str-str-lst (str pat / i)
  (cond ((= str "") nil)
        ((setq i (vl-string-search pat str))
         (cons (substr str 1 i)
               (str-str-lst (substr str (+ (strlen pat) 1 i)) pat)
         ) ;_  cons
        )
        (t (list str))
  ) ;_  cond
) ;_  defun
(SETQ folders '("06112"
                "06113 -Horizon"
                "06113.A -Horizon Addition"
                "06114.A2 -Horizon Addition Revised"
                "06113-Horizon"
                "06113.A-Horizon Addition"
                "06114.A2-Horizon Addition Revised"
               )
)
(vl-load-com)
(setq CFJobNmbrList (mapcar '(lambda(x)(vl-string-trim " " (car(str-str-lst x "-")))) folders))
;RETURN
;("06112" "06113" "06113.A" "06114.A2" "06113" "06113.A" "06114.A2")


VVA

  • Newt
  • Posts: 166
Or other variant
Code: [Select]
;Get Job Name
;path - path (dwgprefix)
;return job name
;Usage
;(get-CFJobNmbr "X:\\Drawings 2006\\06113 -Horizon\\06113.A -Horizon Addition\\")
;Return "06113.A"

(defun get-CFJobNmbr ( path )
  (vl-load-com)
  (defun str-str-lst (str pat / i)
  (cond ((= str "") nil)
    ((setq i (vl-string-search pat str))
     (cons (substr str 1 i)(str-str-lst (substr str (+ (strlen pat) 1 i)) pat)))
        (t (list str))))
  (setq path (last (str-str-lst (vl-string-right-trim " -\\" (vl-princ-to-string path)) "\\")))
  (vl-string-trim " " (car(str-str-lst path "-")))
  )

;Usage
(SETQ folders '("X:\\Drawings 2006\\06113 -Horizon\\06112\\"
                "X:\\Drawings 2006\\06113 -Horizon\\06113 -Horizon\\"
                "X:\\Drawings 2006\\06113 -Horizon\\06113.A -Horizon Addition\\"
                "Z:\\Drawings 2006\\06113 -Horizon\\06114.A2 -Horizon Addition Revised\\"
                "Z:\\Drawings 2006-111\\06113 -Horizon\\06113-Horizon\\"
                "Z:\\Drawings 2006-222222\\06113 -Horizon\\06113.A-Horizon Addition\\"
                "Z:\\Drawings 2006-44444444\\06113 -Horizon\\06114.A2-Horizon Addition Revised\\"
               )
)
(setq CFJobNmbrList (mapcar 'get-CFJobNmbr folders))
;Return ("06112" "06113" "06113.A" "06114.A2" "06113" "06113.A" "06114.A2")


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
How about something like this? <limited testing>
Code: [Select]
(defun Rtrim@ (str tclist / result idx)
  (setq result (mapcar '(lambda(x) (vl-string-search x str)) tclist))
  (if (null result)
    str  ; no trim possible
    (progn
      (mapcar '(lambda(x) (if (numberp x) (setq idx (if idx (min x idx) x)))) result)
      (setq pos (vl-string-search (nth (vl-position idx result) tclist) str))
      (substr str 1 pos)
    )
  )
 )


Code: [Select]
(defun c:test ()
  (setq folders '("06112"
                  "06113 -Horizon"
                  "06113.A -Horizon Addition"
                  "06114.A2 -Horizon Addition Revised"
                  "06113-Horizon"
                  "06113.A-Horizon Addition"
                  "06114.A2-Horizon Addition Revised"
                 )
  )


  (mapcar '(lambda (x) (Rtrim@ x '(" " "-"))) folders)
)
« Last Edit: April 14, 2007, 10:13:30 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

GDF

  • Water Moccasin
  • Posts: 2081
How about using an ini file listing all of your job numbers
See http://www.theswamp.org/index.php?topic=15809.0

This was my solution for listing the project name based upon the job number.
Maybe a variation of it would work for you.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Hangman

  • Swamp Rat
  • Posts: 566
Hey guys, Thank you very much for your help in this.
Sorry I haven't checked back earlier, been ... out of sorts.
I need to look into what you have suggested here, it looks good so far.
A comment was made earlier, (sorry, I'm just using the quick reply, I don't have time to stay at the moment.) about what the criteria is.
I run a program to Bind my drawings.  Right now, the program creates a BIND\ directory.  I want to append to the end of that the job number for easy recognition.
So my drawing - X:\Drawings 2007\06114.A2 -Horizon Addition\06114_A2-S104.dwg, will be bound in directory - X:\Drawings 2007\06114.A2 -Horizon Addition\BIND_06114.A2\ ...
So, I need to extract the job number 06114.A2 from the rest of the directory name to append to the end of the BIND in my program.
As you can see, if the job number is 06113, it's not a problem.  But if I have 06114.A - SOME NAME or 06114.A2 -SOME NAME, then it gets a little more challenging.
Thanks again guys.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~