+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Forum Newbie ehsantavassolian's Avatar
    Discipline
    Surveying
    ehsantavassolian's Discipline Details
    Occupation
    Civil Engineer
    Discipline
    Surveying
    Using
    AutoCAD 2012
    Join Date
    Oct 2017
    Location
    Iran tehran
    Posts
    7

    Unhappy How can I translate \ to \\

    Registered forum members do not see this ad.

    i want to translate \ to \\
    For Example translate
    "\\Pc1\source"
    to
    "\\\\Pc1\\source"

    I wrote this
    (vl-string-translate "\" "\\" "\\Pc1\source")
    But there is a problem
    The system does not accept "\"

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,501

    Default

    A single backslash in AutoLISP is an Escape Character, used to give an alternative meaning to characters which follow it (e.g. "\t" is the tab character). Therefore, before you pass the input string to an AutoLISP expression, you will first need to correctly represent the backslashes as literal backslashes within the string:
    Code:
    _$ (setq str "\\\\Pc1\\source")
    "\\\\Pc1\\source"
    Note that this will be printed with half the number of backslashes:
    Code:
    _$ (progn (princ str)(princ))
    \\Pc1\source
    Now, if you really wish to double the number of backslashes in the output string, there are a number of ways to accomplish this - here is one way:
    Code:
    _$ (vl-string-trim "\"" (vl-prin1-to-string str))
    "\\\\\\\\Pc1\\\\source"
    This output string will then be printed:
    Code:
    _$ (progn (princ (vl-string-trim "\"" (vl-prin1-to-string str)))(princ))
    \\\\Pc1\\source
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Senior Member
    Computer Details
    Stefan BMR's Computer Details
    Operating System:
    Win10
    Discipline
    Structural
    Using
    AutoCAD 2019
    Join Date
    Sep 2011
    Location
    Baia Mare, Romania
    Posts
    389

    Default

    The string "\s" is 1 char length. You can check it.
    Code:
    (strlen "\s") -> 1
    (substr "\s" 1) -> "s"
    It is impossible to even set a variable to your source string.
    So first thing is to check your variable. Try both (princ my_var) and (prin1 my_var), the real content of the variable is what the prin1 returns.

  4. #4
    Forum Newbie ehsantavassolian's Avatar
    Discipline
    Surveying
    ehsantavassolian's Discipline Details
    Occupation
    Civil Engineer
    Discipline
    Surveying
    Using
    AutoCAD 2012
    Join Date
    Oct 2017
    Location
    Iran tehran
    Posts
    7

    Unhappy Thanks for your description

    Thanks for your description
    I learned your training
    I tried a lot . But it's not working properly on this example

    \\Pc1\source

    Intended character is deleted

    \\\\Pc1source

  5. #5
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    943

    Default

    Quote Originally Posted by ehsantavassolian View Post
    Thanks for your description
    I learned your training
    I tried a lot . But it's not working properly on this example

    \\Pc1\source

    Intended character is deleted

    \\\\Pc1source
    There are only 2 ways you can enter this string :

    Code:
     (setq path "\\\\Pc1\\source")
    or
    Code:
     (setq path "//Pc1/source")
    even if your path is read from a (text)file lisp would automaticly translate "\\Pc1\source" to "\\\\Pc1\\source" so if you yourself enter this path manually you must use this string as shown above in your lisp code. If you let a user enter the path through a getstring you would get something like this :

    Command: (setq path (getstring "\nPath : "))
    Path : \\pc1\source <- you type one double and one single backslash
    "\\\\pc1\\source" <- lisp automaticly translates this to four and two backslashes


    gr. Rlx

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,501

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by ehsantavassolian View Post
    I tried a lot . But it's not working properly on this example

    \\Pc1\source

    Intended character is deleted

    \\\\Pc1source
    The backslash character is not 'deleted' as it was never there in the first place - per my post above, a single backslash in AutoLISP is an Escape Character. If you want to represent a backslash in an AutoLISP string, you need to prefix it with another backslash to mark it as a literal backslash and not an Escape Character.

    Please re-read my post above.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Translate english to ?
    By wastewater in forum AutoCAD General
    Replies: 7
    Last Post: 15th Feb 2016, 10:12 am
  2. vl-string-translate
    By Happy Hobbit in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 6th Nov 2015, 06:54 am
  3. vl-string-translate
    By muthu123 in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 14th Jul 2010, 08:02 pm
  4. translate please
    By guitarguy1685 in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 4th Dec 2009, 09:35 am
  5. Translate point to current UCS
    By chavlji in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 21st Feb 2009, 12:31 am

Bookmarks

Posting Permissions

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