admin 管理员组文章数量: 1086019
I am having difficulties handling symbol \ in javascript. Strings seems to ignore it, for example alert('a\b')
would only alert a
.
My goal is to write following function which would give me latex image:
function getLatexImage(tex)
{
return ';chl=' + tex;
}
However calling getLatexImage('\frac{a}{b}')
gives me: ";chl=rac{a}{b}"
\f
is being ignored.
Any suggestions?
I am having difficulties handling symbol \ in javascript. Strings seems to ignore it, for example alert('a\b')
would only alert a
.
My goal is to write following function which would give me latex image:
function getLatexImage(tex)
{
return 'http://chart.apis.google./chart?cht=tx&chl=' + tex;
}
However calling getLatexImage('\frac{a}{b}')
gives me: "http://chart.apis.google./chart?cht=tx&chl=rac{a}{b}"
\f
is being ignored.
Any suggestions?
Share Improve this question asked Sep 7, 2015 at 8:41 WagmWagm 3686 silver badges13 bronze badges 3- 1 escape the symbol -put '\\' instead of '\' – Ivaylo Strandjev Commented Sep 7, 2015 at 8:42
- See msdn.microsoft./library/2yfce773(v=vs.94).aspx – Tushar Commented Sep 7, 2015 at 8:42
- Pretty sure you could have used search to find this question... – akalikin Commented Sep 7, 2015 at 8:49
4 Answers
Reset to default 4\
is an escape character. It starts an escape sequence.
\n
is a new line. \t
is a tab. An escape sequence that has no special meaning usually gets turned into the character on the RHS (so \b
is b
).
To have a backslash as data in a string literal you have to escape it:
alert('a\\b');
Use \\
. Single slashes are used for special signs (like \n
, \t
..)
The backslash \
is a escape character in JavaScript and many other programming languages. If you want to output it, you'll need to escape it by itself.
\\a
for example would output \a
.
That being said, if you want to use it in an url you should encode it for safety.
%5c
translates to \
You can simply escape it by adding another backslash
'\\b'
本文标签: Javascript strings with symbol 3939Stack Overflow
版权声明:本文标题:Javascript strings with symbol '' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744036711a2522499.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论