Jump to content

Recommended Posts

Posted

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?

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • DGRL

    13

  • rlx

    4

  • rkmcswain

    3

  • ronjonp

    3

Top Posters In This Topic

Posted Images

Posted

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

_$

Posted

You could also do it like this

 

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

Posted

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?

Posted
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 "\"")

Posted

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

Posted

READING CODE IS IMPORTANT

 

 

And tricking me is nasty LOL

Posted
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)

Posted

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

Posted
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

Posted

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

Posted

@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

Posted
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

Posted

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".

Posted
@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.

Posted

Simple test

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

Posted

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

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...