Results 1 to 7 of 7

Thread: Reduce String length by a certain number of characters

  1. #1
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Reduce String length by a certain number of characters

    Hi

    Is there a way to reduce a string length to a user specified number of characters using Visual Lisp?

    Example Reduce “ABCDEFGH” to “DEFGH”

    With the user specifying how many characters to trim?

    John

  2. #2
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Reduce String length by a certain number of characters

    Quote Originally Posted by jmcshane View Post
    Hi

    Is there a way to reduce a string length to a user specified number of characters using Visual Lisp?

    Example Reduce “ABCDEFGH” to “DEFGH”

    With the user specifying how many characters to trim?

    John
    yes,
    you can use:
    Code:
    (setq number (getint "\nSpecify number of characters to trim\n"))
    (substr "ABCDEFGH" number)
    Havent tested, but Help says that is the proper syntax

  3. #3
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Reduce String length by a certain number of characters

    That's exactly it.
    Something so simple.

    Many Thanks

    John

  4. #4
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Reduce String length by a certain number of characters

    If you want to trim from the end of the string (instead of the start), then this should work:
    Code:
    (setq str "ABCDEFGH")
    (substr str 1 (- (strlen str) number))

  5. #5
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Reduce String length by a certain number of characters

    Thanks Irneb,

    I was trying all this vl-string-trim left and right and forgot all about the simple substr command.

    I got it to work in the end anyway.

    Many thanks

    John

  6. #6
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Reduce String length by a certain number of characters

    You're welcome!

    I can understand your reasoning ... having programmed in several other languages, when I 1st saw it I also thought string-trim aha!

    Although the AutoLisp (or rather VisualLisp) vl-string-trim is more like a string cleanup than a trim. Thankfully it is explained in the help though .

  7. #7
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Reduce String length by a certain number of characters

    Help???????


    www.augi.com is the best manual on the market.

Similar Threads

  1. 2015: Status Bar length cut to 56 characters.
    By Tom Beauford in forum AutoCAD CUI Menus
    Replies: 0
    Last Post: 2014-06-11, 12:17 PM
  2. Reduce the Number of Defaults in the Layer Key
    By Sheri_in_CA in forum AMEP Wish List
    Replies: 0
    Last Post: 2008-01-17, 10:45 PM
  3. Remove characters from a string
    By ccowgill in forum AutoLISP
    Replies: 9
    Last Post: 2006-10-03, 08:29 AM
  4. Reduce number of lines displayed in the AutoCAD Command Line
    By neilcheshire in forum AutoCAD LT - General
    Replies: 4
    Last Post: 2006-09-14, 04:29 PM
  5. Remove all " characters from a string
    By rwbaker in forum VBA/COM Interop
    Replies: 8
    Last Post: 2006-02-01, 04:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •