Author Topic: Strcat text with a list  (Read 3066 times)

0 Members and 1 Guest are viewing this topic.

Cawaugh

  • Guest
Strcat text with a list
« on: January 02, 2007, 11:06:45 AM »
(write-line (strcat "(find_replace " includetxt " " mdwg " " mstringlist " " SearchAtt " " case " " firstonly ")") Ofil)

The above gives me an error which I believe is due to trying to strcat text with lists. mstringlist and SearchAtt are lists. How can I get these lists into a script file with write-line? What I am trying to do is pass a list as an argument to the find_replace function. When the script is run it has this as a line to be read:
(find_replace "1" "y" list-of-strings-to-look-for list-of-atts-to-search-through "1" "1")
Thanks in advance for any help. :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Strcat text with a list
« Reply #1 on: January 02, 2007, 11:27:28 AM »
Chuck,

  When you want to string characters (strcat) and an item is a list, use 'vl-princ-to-string' for that item.  So something like
Code: [Select]
(strcat
 "Happy"
 (vl-princ-to-string '(1 2 3 45))
 (setq Test " This is a test. ")
)
Returns
Quote
"Happy(1 2 3 45) This is a test. "

Hope that helps.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Strcat text with a list
« Reply #2 on: January 02, 2007, 11:54:26 AM »
Breaking this down:
Code: [Select]
(write-line (strcat "(find_replace " includetxt " " mdwg " " mstringlist "
                                           " SearchAtt " " case " " firstonly ")") Ofil)

It would appear that find_replace takes several string arguments
Code: [Select]
(find_replace " includetxt " " mdwg " " mstringlist " " SearchAtt " " case " " firstonly ")
And returns a string that is then written to a file.

If that is the case then no strcat is needed.
Code: [Select]
(write-line (find_replace " includetxt " " mdwg " " mstringlist " " SearchAtt " " case " " firstonly ") Ofil)
If that is not the case then more information on the find_replace function is needed.
« Last Edit: January 02, 2007, 11:55:30 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Cawaugh

  • Guest
Re: Strcat text with a list
« Reply #3 on: January 03, 2007, 09:57:46 AM »
Chuck,

  When you want to string characters (strcat) and an item is a list, use 'vl-princ-to-string' for that item.  So something like
Code: [Select]
(strcat
 "Happy"
 (vl-princ-to-string '(1 2 3 45))
 (setq Test " This is a test. ")
)

Returns
Quote
"Happy(1 2 3 45) This is a test. "

Hope that helps.

What I am finding out is that I cannot get a list written out so that when the script is run the below setq will not work. I'm trying to set the variable mstringlist to a list but the strcat won't let me.
(write-line (strcat "(setq " "mstringlist " mstringlist ")") Ofil)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Strcat text with a list
« Reply #4 on: January 03, 2007, 11:15:29 AM »
Maybe this
Code: [Select]
(write-line
 (strcat
  "(find_replace "
  includetxt
  " "
  mdwg
  " "
  (vl-princ-to-string mstringlist)
  " "
  (vl-princ-to-string SearchAtt)
  " "
  case
  " "
  firstonly
  ")"
 )
 Ofil
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Strcat text with a list
« Reply #5 on: January 03, 2007, 11:59:28 AM »
Boy, I sure missed that one. :-o
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Strcat text with a list
« Reply #6 on: January 03, 2007, 12:14:08 PM »
Boy, I sure missed that one. :-o
Thats okay, you can have the next one then  Alan.   :-D
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.