从最简单的解释开始,得出最终结论:
当您有一个字符串变量时,其内容必须用双引号包装:“
示例:“这是我的字符串”
strcat函数需要多个字符串参数,以便将它们合并在一起:
- (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")
现在知道了这一点,很明显,如果您试图手动添加一个“,解释器会希望您也放上结束符“来完成字符串包装,通过点击回车键,您可以看到“_>
例子:
- _$ "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"
现在,通过了解所有这些内容,关于逻辑是什么-那么如何在字符串中包含实际的“字符”?
就像Rlx告诉你的那样,你必须使用“来获得”
- (alert "Now I'll put this "string" in my double quotes")
代码中的字符串可能会让您感到困惑,但解释器会检查双引号前的“\”,然后知道他必须逐字传递它。
现在棘手的部分是,当您将其与strcat函数一起使用时,您必须注意如何使用“(双引号):
- _$ (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]
顺便说一句,你注意到字符串“my string is finished now”中的“\n”了吗?那是什么?这是一个换行符,我刚刚按下enter键,解释器就这样翻译了它,所以它知道:
“看,n前面有,这意味着这是一个换行符,而不是‘n’字母”。 |