DGRL Posted April 16, 2018 Posted April 16, 2018 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? Quote
DGRL Posted April 16, 2018 Author Posted April 16, 2018 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 _$ Quote
rkmcswain Posted April 16, 2018 Posted April 16, 2018 You could also do it like this (strcat "sometext " (chr 34) "EXTRATEXT" (chr 34)) Quote
DGRL Posted April 16, 2018 Author Posted April 16, 2018 Well i think i need some 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? Quote
ronjonp Posted April 16, 2018 Posted April 16, 2018 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 "\"") Quote
DGRL Posted April 16, 2018 Author Posted April 16, 2018 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 Quote
DGRL Posted April 16, 2018 Author Posted April 16, 2018 READING CODE IS IMPORTANT And tricking me is nasty LOL Quote
ronjonp Posted April 16, 2018 Posted April 16, 2018 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. Quote
rlx Posted April 16, 2018 Posted April 16, 2018 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 Quote
rkmcswain Posted April 16, 2018 Posted April 16, 2018 Well i think i need some 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: Quote
DGRL Posted April 16, 2018 Author Posted April 16, 2018 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 Quote
DGRL Posted April 16, 2018 Author Posted April 16, 2018 @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 Quote
ronjonp Posted April 16, 2018 Posted April 16, 2018 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. Quote
Grrr Posted April 16, 2018 Posted April 16, 2018 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". Quote
rkmcswain Posted April 16, 2018 Posted April 16, 2018 @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. Quote
hanhphuc Posted April 16, 2018 Posted April 16, 2018 Simple test (setq $ (getstring t "\nType your text here with quote mark : ")) (print $)(princ) Quote
DGRL Posted April 17, 2018 Author Posted April 17, 2018 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 Quote
rlx Posted April 17, 2018 Posted April 17, 2018 (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 April 17, 2018 by rlx Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.