vl-string-right-trim

Discussion in 'AutoCAD' started by jclaidler, Aug 26, 2003.

  1. jclaidler

    jclaidler Guest

    Is there a way to trim a desired number of characters and/or spaces ?? For example, remove abcd from 1234abcd.
     
    jclaidler, Aug 26, 2003
    #1
  2. jclaidler

    jclaidler Guest

    Can you start from the end of the string ??
     
    jclaidler, Aug 26, 2003
    #2
  3. No but you can determine the starting position of the string you wish to remove using vl-string-position then retrieve the portion of the string from position one to position N - 1.




    --
    There are 10 kinds of people. Those who understand binary and those who don't.



     



    http://code.acadx.com




    "jclaidler" <-usa.com> wrote in message news:...

    Can you start from the end of the string ??
     
    Frank Oquendo, Aug 26, 2003
    #3
  4. ; CarDlm = character to subst or remove
    ; NewDlm = new string for subst or "" for remove
    ; StgVal = original string

    (defun ALE_StringSubst (CarDlm NewDlm StgVal / AscDel)
    (setq AscDel (ascii CarDlm))
    (while (vl-string-position AscDel StgVal)
    (setq StgVal (vl-string-subst NewDlm CarDlm StgVal))
    )
    StgVal
    )

    ; Original : "abcd1234abcd1234abcd"
    ; To remove: "abcd"

    (ALE_StringSubst
    "@" ""
    (vl-string-translate "abcd" "@@@@" "abcd1234abcd1234abcd")
    )

    ; Result: "12341234"

    --
     
    Marc'Antonio Alessi, Aug 26, 2003
    #4
  5. jclaidler

    Michel Guest

    The title of your message say it all !!!

    (vl-string-right-trim "abcd" "1234abcd")

    jclaidler a écrit :
     
    Michel, Aug 26, 2003
    #5
  6. No joke? I just learned something new. Thanks!

    :)
     
    Frank Oquendo, Aug 26, 2003
    #6
  7. or better:

    ;
    ; Multiple substitution of a pattern string - 05/21/03
    ; Original by John Uhden, added SttPos argument
    ;
    ; Arguments:
    ; NewStr: the string to be substituted for pattern
    ; PatStr: a string containing the pattern to be replaced
    ; InpStr: the string to be searched for pattern
    ; SttPos: 0, nil or an integer identifying the starting position of the
    search
    ;
    ; Return Values: the value of string after any substitutions have been made
    ;
    ; Example:
    ; (ALE_StringSubstAll "new" "old" "old test for old method" nil)
    ;
    ; Notes:
    ; the search is case-sensitive
    ; SttPos = 0 or nil > substitution start from first character
    ; NewStr = "" remove all instances of PatStr from SttPos
    ;
    ; Suggestions:
    ; use (vl-string-translate "\t" " " "Hi\tthis\tis\ta\ttest!")
    ; for single (or set) character substitution (not to remove)
    ; (N.B. the inversion of arguments)
    ;
    (defun ALE_StringSubstAll (NewStr PatStr InpStr SttPos / NewLen)
    (setq NewLen (strlen NewStr))
    (while (setq SttPos (vl-string-search PatStr InpStr SttPos))
    (setq
    InpStr (vl-string-subst NewStr PatStr InpStr SttPos)
    SttPos (+ SttPos NewLen)
    )
    )
    InpStr
    )
     
    Marc'Antonio Alessi, Aug 26, 2003
    #7
  8. jclaidler

    Michel Guest

    So you know what the first 12 caracters are ok..then

    (setq Bname "720-1264-002-02223a")
    (setq FirstPartPart (substr Bname 1 12))
    (setq LastPart (substr Bname 13))

    jclaidler a écrit :
     
    Michel, Aug 26, 2003
    #8
  9. jclaidler

    jclaidler Guest

    nope... the constant will be "-##### then letter" or nothing at the end of the block.
     
    jclaidler, Aug 26, 2003
    #9
  10. jclaidler

    Michel Guest

    With all the suggestions.....you should have the solution...or explain
    the
    problem clearly.

    jclaidler a écrit :
     
    Michel, Aug 26, 2003
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.