Replace " with \" in a string

Replace " with \" in a string

svucic
Advocate Advocate
950 Views
6 Replies
Message 1 of 7

Replace " with \" in a string

svucic
Advocate
Advocate

Hi everyone,

 

as the title says i'm trying to replace the quotes in a path with \".

 

Example:

 

"C:\\Users\\Something\\Desktop\\Something"

 

to

 

\"C:\\Users\\Something\\Desktop\\Something\"

0 Likes
Accepted solutions (1)
951 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

What is it? Content of an (M)TEXT entity?

 

Spoiler
; if so, then getting string of a content
(cdr (assoc 1 (entget (car (entsel)))))

receive
"\"C:\\\\Users\\\\Something\\\\Desktop\\\\Something\""


Or a value of a STRING variable?

0 Likes
Message 3 of 7

svucic
Advocate
Advocate

It's a value of a STRING variable.

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

Try this...

 

(strcat "\"" "C:\\Users\\Something\\Desktop\\Something" "\"")

 

or if you have a variable called filepath, then

 

(strcat "\"" filepath "\"")

 

which gives you

 

"\"C:\\Users\\Something\\Desktop\\Something\""

 

Outer quotation marks are a part of a string definition, can't omit those.

0 Likes
Message 5 of 7

svucic
Advocate
Advocate

Wel, I'm using (setq DirPath (acet-ui-pickdir)) to get the path to a folder which I'm passing to an external program. 

 

And the path that i'm passing to the program should be like this:

\"C:\\Users\\Srdjan\\Documents\\test.csv\"

 

Example of executing external program:

 

(dos_execute "program -input:\"C:\\Users\\Something\\Desktop\\Something\" -output:\"C:\\Users\\Something\\Desktop\\Something\" -definition:\"C:\\Users\\Something\\Desktop\\Something\"" 0)

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

@svucic wrote:

Wel, I'm using (setq DirPath (acet-ui-pickdir)) to get the path to a folder which I'm passing to an external program. 

 

And the path that i'm passing to the program should be like this:

\"C:\\Users\\Srdjan\\Documents\\test.csv\"

 

Example of executing external program:

 

(dos_execute "program -input:\"C:\\Users\\Something\\Desktop\\Something\" -output:\"C:\\Users\\Something\\Desktop\\Something\" -definition:\"C:\\Users\\Something\\Desktop\\Something\"" 0)


Try something like this...

 

(setq filepath "C:\\Users\\Something\\Desktop\\Something")
(setq filepathquited (strcat "\"" filepath "\""))

(setq depars (strcat "program"
                     " -input:" filepathquited
                     " -output:" filepathquited
                     " -definition:" filepathquited))

(dos_execute depars 0)

 

Or, it may be more obvious without variables...

 

(dos_execute (strcat "program"
                     " -input:" "\"" filepath "\""
                     " -output:" "\"" filepath "\""
                     " -definition:" "\"" filepath "\"")
  0)

 

Message 7 of 7

svucic
Advocate
Advocate

Works. Thank you BeeKeeCZ 🙂

0 Likes