Double quotes within a string

Double quotes within a string

Anonymous
Not applicable
2,275 Views
4 Replies
Message 1 of 5

Double quotes within a string

Anonymous
Not applicable
(setq FILEPATH "D:\\test\\csvextract\\Errorlog.txt") ;FILEPATH is a variable


I want to write below line as it is to a text file. Assume that is "D:\\dummy.txt"

(see "notepad" "D:\\test\\csvextract\\Errorlog.txt")

I want to use FILEPATH variable to achieve the above line in that text file. please help.

0 Likes
2,276 Views
4 Replies
Replies (4)
Message 2 of 5

regisrohde
Advocate
Advocate
(setq FILETXTOPEN (open FILEPATH "R"))
(setq txtLine (read-line FILETXTOPEN ))
Please mark this as the solution if it resolves your issue.Kudos gladly accepted.
Regis Rohde
Message 3 of 5

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
I want to write below line as it is to a text file. ....
(see "notepad" "D:\\test\\csvextract\\Errorlog.txt")
I want to use FILEPATH variable to achieve the above line in that text file. please help.

I thought this should work, with \" to get the quotation marks into your output string:

 

 

(setq
  test (open "C:\\test.txt" "w"); EDIT for your file path/name
  FILEPATH "D:\\test\\csvextract\\Errorlog.txt"
)
(write-line
  (strcat "(see \"notepad\" \"" FILEPATH "\")")
  test
)
(close test)

But I find that results in this string in the file:

 

(see "notepad" "D:\test\csvextract\Errorlog.txt")

 

with single backslashes.  Will whatever you're doing with that file work if it's that way?  It's possible to double them [replace the double ones in the FILEPATH variable's string with four each], but it's kind of complicated, because the (vl-string-subst) function does the substitution for only the first instance it finds, which means the string needs to be broken into pieces, the backslashes in the pieces replaced with double ones, and the overall string put back together again.  There are routines around here to break strings around designated characters, that can be incorporated, but if you can use it with the single backslashes, the above will serve.

Kent Cooper, AIA
Message 4 of 5

dbroad
Mentor
Mentor

In addition to what Kent said, the following sequence can pretty much get back the concatenated string:

 

(setq fh (open "D:\\dummy.txt" "r"))
(setq test (read-line fh))

 

 

Architect, Registered NC, VA, SC, & GA.
Message 5 of 5

Anonymous
Not applicable

Hi,

thanks a lot all of you for responding.

 

here i find a way to do it.

 

 

(setq filepath "D:\\test\\CSVEXTRACT\\Errorlog.txt")





(setq afile (open "d:\\dummy.txt" "w"))




(princ "(see \"notepad\" " afile)




(prin1 filepath afile)




(princ ")" afile)




(close afile)

 

 

 

 

Then i have opened the file "dummy.txt" to find this line:

 

(see "notepad" "D:\\test\\CSVEXTRACT\\Errorlog.txt")

 

I need to use this line in a script file actually.

 

I have replaced see with startapp. Then it served my purpose.

0 Likes