Jump to content
DGRL

Include " when using STRCAT

Recommended Posts

DGRL

Dear coders

 

 

I am trying to include " when using strcat

Afaik you need to use \ or / in combinatiuon with extra " to get "something here" when using strcat

 

 

So I want to do this

 

 

(strcat "sometext" "" EXTRATEXT"" )

 

 

As you can see the EXTRATEXT needs to be in quotes

I tried

(strcat "sometext" "\" EXTRATEXT""\ )

but also

(strcat "sometext" \"" EXTRATEXT"\" )

 

 

and a few other but none of them works

How can I strcat something that needs to stay in quotes?

Share this post


Link to post
Share on other sites
rlx

to get a " you have to use "\""

Share this post


Link to post
Share on other sites
DGRL

THNX M8 I just forgot the extra " :facepalm:

Share this post


Link to post
Share on other sites
DGRL

RLX

What the hell am I doing wrong

 

 

(strcat "sometext" "\"" EXTRATEXT"\"" )

; error: bad argument type: stringp nil

 

 

 

 

_$ (strcat "sometext" "\"" EXTRATEXT""\" )

("_> ")

; error: bad argument type: stringp nil

_$

Share this post


Link to post
Share on other sites
rkmcswain

You could also do it like this

 

(strcat "sometext " (chr 34)  "EXTRATEXT" (chr 34))

Share this post


Link to post
Share on other sites
DGRL

Well i think i need some :danger: to use at my pc coz i am getting wicked results

 

 

$ (strcat "sometext " (chr 34) "EXTRATEXT" (chr 34))

"sometext \"EXTRATEXT\""

 

 

What in the world is the \ doing up there?

Share this post


Link to post
Share on other sites
ronjonp
RLX

What the hell am I doing wrong

 

 

(strcat "sometext" "\"" EXTRATEXT"\"" )

; error: bad argument type: stringp nil

 

 

 

 

_$ (strcat "sometext" "\"" EXTRATEXT""\" )

("_> ")

; error: bad argument type: stringp nil

_$

 

See if this turns on a light bulb:

(setq extratext "some more text")
(strcat "sometext" "\"" extratext "\"")
(setq extratext nil)
(strcat "sometext" "\"" extratext "\"")

Share this post


Link to post
Share on other sites
DGRL

RLX

 

 

Light bulb is starting to give light but in the end it turns to be STRINGP NIL

 

 

_$ (setq extratext "some more text")

"some more text"

_$ (strcat "sometext" "\"" extratext "\"")

"sometext\"some more text\""

_$ (setq extratext nil)

nil

_$ (strcat "sometext" "\"" extratext "\"")

; error: bad argument type: stringp nil

_$

 

 

I am getting confused by this

Share this post


Link to post
Share on other sites
DGRL

READING CODE IS IMPORTANT

 

 

And tricking me is nasty LOL

Share this post


Link to post
Share on other sites
ronjonp
READING CODE IS IMPORTANT

 

 

And tricking me is nasty LOL

 

I'm not tricking you, I'm trying to get you to see what causes that error. 8)

Share this post


Link to post
Share on other sites
rlx

it all depends what your trying to do , if you want to pass a filename or command in a script and use " you would use

 

 

 (write-line "(while (= 1 (logand (getvar \"cmdactive\") 1))(command \"Yes\"))" fp) 

but my workday is done so closing shop here... I leave you at the more than capable hands of RonjonP & rkmcswain

Share this post


Link to post
Share on other sites
rkmcswain
Well i think i need some :danger: to use at my pc coz i am getting wicked results

 

 

$ (strcat "sometext " (chr 34) "EXTRATEXT" (chr 34))

"sometext \"EXTRATEXT\""

 

 

What in the world is the \ doing up there?

 

Yes, it will return that at the command prompt, but plug that code into something else.

 

For example:

 

(alert (strcat "sometext " (chr 34)  "EXTRATEXT" (chr 34)))

 

Returns this:

 

UlgZocy.png

Share this post


Link to post
Share on other sites
DGRL

hmmmm

 

 

Well how can i make an error when i am not using variables.

 

 

DO NOT GIVE ME THEN ANSWER I WILL THINK IF THIS

Bud you saw that i made an error so i will think of this for a few minutes to see if i can see what you already saw

 

 

Thanks for the help so far

Share this post


Link to post
Share on other sites
DGRL

@rkmcswain

 

 

I am not using this in an alert but to set it as variable

When using the alert in AutoCAD i get same result as you but when writing to an variable i get the extra / which messes up my code

Share this post


Link to post
Share on other sites
ronjonp
hmmmm

 

Well how can i make an error when i am not using variables.

....

What editor are you using? It's easily identifiable in the Vlide that you ARE using a variable even if you don't mean to.

2018-04-16_7-57-40.png

Share this post


Link to post
Share on other sites
Grrr

Start with the most simple explanations, to get the end conclusion:

 

When you have a string variable, its content must be wrapped with double quotes: " "

Example: "this is my string"

The strcat function expects multiple string arguments, in order to merge them together:

(strcat
 "First string"
 "Second string"
 "Third string"
)
[color="darkgreen"]; The above, condensed in one row it looks like this (which would help you to mess-up your double quotes understanding) :[/color]
(strcat "First string" "Second string" "Third string")

 

Now by knowing this, obviously if you try to add manually a ", the interpreter would expect you to put the closing " aswell, to finish the string wrapping, and by hitting enter you can see "_>

Example:

_$ "my string is
"_> finished now" [color="darkgreen"]; the interpreter hints with "_> that it expects a closing "[/color]
"my string is\nfinished now"

 

_$ (strcat "My string
("_> " [color="darkgreen"]; the interpreter hints with "_> that it expects a closing " and a closing ')'[/color]
(_> ", my next string" [color="darkgreen"]; the interpreter hints with (_> a closing ')'[/color]
(_> )[color="darkgreen"]; I'll close the ), for the (strcat) function[/color]
"My string\n, my next string"

 

Now by knowing all that stuff, about whats the logic - then how to include the actual " character in the string?

Like Rlx told you, you have to use \" to get a "

 

(alert "Now I'll put this \"string\" in my double quotes")

The string inside the code may confuse you, but interpreter checks the '\' infront the double quote ", and then knows that he has to pass it literally.

 

Now the tricky part is when you use along it with the strcat function, you have to be careful how you put your " (double-quotes) :

_$ (setq MyVariable "DGRL")
"DGRL"
_$ (strcat "My nickname is " MyVariable " and I'm on cadtutor") [color="darkgreen"]; notice the dobule-quote separators for (strcat)[/color]
"My nickname is DGRL and I'm on cadtutor"
_$ (strcat "My nickname is [b][color="red"]\"[/color][/b]" MyVariable "[b][color="red"]\"[/color][/b] and I'm on cadtutor") [color="darkgreen"]; adding the literal quotes, notice that the dobule-quote separators for (strcat) remain the same[/color]
"My nickname is [b][color="red"]\"[/color][/b]DGRL[b][color="red"]\"[/color][/b] and I'm on cadtutor" [color="darkgreen"]; but it still looks confusing ![/color]
_$ (alert "My nickname is [b][color="red"]\"[/color][/b]DGRL[b][color="red"]\"[/color][/b] and I'm on cadtutor") [color="darkgreen"]; but the interpreter does his job, so when alerting it we'll be ok[/color]

 

BTW did you notice the '\n' from the string "my string is\nfinished now" ? Whats that '\n' ? Its a newline character, I just pressed enter and the interpreter translated it like that so it knows:

"Look theres \ infront of that n, which means this is a newline and not the 'n' letter".

Share this post


Link to post
Share on other sites
rkmcswain
@rkmcswain

 

 

I am not using this in an alert but to set it as variable

When using the alert in AutoCAD i get same result as you but when writing to an variable i get the extra / which messes up my code

 

Did you actually try it, or are you just reading the command line?

Let's break it down

 

(setq var "SAMSUNG") ;<- a string
(setq str (strcat 
   "My TV is a " ;<- a string
   (chr 34)      ;<- a string
    var          ;<- a string
   (chr 34)      ;<- a string
              )
)
(progn (princ str)(princ)) ; returns 

;; My TV is a "SAMSUNG" 

 

No extra slashes or quote marks, etc.

 

When you read the output at the command line, it will always show you the "\" marks. The symbol itself does not include them.

Share this post


Link to post
Share on other sites
hanhphuc

Simple test

(setq $ (getstring t "\nType your text here with quote mark : "))
(print $)(princ)

Share this post


Link to post
Share on other sites
DGRL

Guys

 

 

This line needs to be STRCAT

 

 

reg.exe add "HKEY_CURRENT_USER\Software\Autodesk\Autocad\R19.1\ACAD-D001:409\Profiles\>\Variables" /v "SECURELOAD" /t REG_SZ /d "1" /f

 

 

Some have " and some not

The one's the does not have the " are seen as variables (DUH) but I am struggling getting this in 1 line using strcat

The line NEEDS to stay like this when putting it in an variable

 

 

So what I want is

 

 

(setq VAR (strcat reg.exe add "HKEY_CURRENT_USER\Software\Autodesk\Autocad\R19.1\ACAD-D001:409\Profiles\>\Variables" /v "SECURELOAD" /t REG_SZ /d "1" /f))

 

 

When type VAR you will get --> reg.exe add "HKEY_CURRENT_USER\Software\Autodesk\Autocad\R19.1\ACAD-D001:409\Profiles\>\Variables" /v "SECURELOAD" /t REG_SZ /d "1" /f

Share this post


Link to post
Share on other sites
rlx
Posted (edited)

this???

(setq VAR "reg.exe add \"HKEY_CURRENT_USER\\Software\\Autodesk\\Autocad\\R19.1 [url="file://\\ACAD-D001:409\\Profiles\\<<Unnamed"]\\ACAD-D001:409\\Profiles\\<<Unnamed[/url] Profile>>\\Variables\" /v \"SECURELOAD\" /t REG_SZ /d \"1\" /f")

Edited by rlx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×