Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何在长生不老药字符串中嵌入双引号?_String_Elixir_Double Quotes - Fatal编程技术网

String 如何在长生不老药字符串中嵌入双引号?

String 如何在长生不老药字符串中嵌入双引号?,string,elixir,double-quotes,String,Elixir,Double Quotes,我有一个刺已经嵌入了“: tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture"> tx 如何在Elixir中将这样的字符串表示为值 例如: iex> s= "tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">" iex>s=“tx”

我有一个刺已经嵌入了

tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">
tx
如何在Elixir中将这样的字符串表示为值

例如:

iex> s= "tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">"
iex>s=“tx”
使用~s和~s没有帮助

iex(20)> s=~S("tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">")              
** (SyntaxError) iex:20: keyword argument must be followed by space after: w:

iex(20)> s=~s("tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">")
** (SyntaxError) iex:20: keyword argument must be followed by space after: w:

iex(20)> 
iex(20)>s=~s(“tx”)
**(SyntaxError)iex:20:keyword参数必须在:w:
iex(20)>s=~s(“tx”)
**(SyntaxError)iex:20:keyword参数必须在:w:
iex(20)>

您可以对双引号进行转义:

s ="tx <iq id=\"wUcdTMYuYoo41\" to=\"2348138248411@\" type=\"set\" xmlns=\"w:profile:picture\">"
s=“tx”
有一种方法可以使这更方便(还有一种方法不插值变量):

s=~s(tx)
使用多行字符串(heredocs)时也会转义引号:

“”“
德克萨斯州
"""

符号就是这样,你只需要在等号后面加一个空格:

iex(1)> s = ~s("tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">")
"\"tx <iq id=\"wUcdTMYuYoo41\" to=\"2348138248411@\" type=\"set\" xmlns=\"w:profile:picture\">\""

iex(2)> s = ~S("tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">")
"\"tx <iq id=\"wUcdTMYuYoo41\" to=\"2348138248411@\" type=\"set\" xmlns=\"w:profile:picture\">\""
iex(1)>s=~s(“tx”)
“\“tx”
iex(2)>s=~s(“tx”)
“\“tx”

谢谢。当我们从文件.stream中提取这样的字符串时!(“path/to/File”)是否也需要这样做?在返回的每一行上?使用
File.stream
将自动转义引号。例如
iex(4)>IO.get“>”;>“>TEST”“;“\”\“\”\“\”\“\”\n”
请~s和~s不起作用请查看上面编辑的问题中报告的错误您需要在
~
-
s=~s(…)
s=~s(…)
"""
tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">
"""
iex(1)> s = ~s("tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">")
"\"tx <iq id=\"wUcdTMYuYoo41\" to=\"2348138248411@\" type=\"set\" xmlns=\"w:profile:picture\">\""

iex(2)> s = ~S("tx <iq id="wUcdTMYuYoo41" to="2348138248411@" type="set" xmlns="w:profile:picture">")
"\"tx <iq id=\"wUcdTMYuYoo41\" to=\"2348138248411@\" type=\"set\" xmlns=\"w:profile:picture\">\""