admin管理员组文章数量:1310074
Having this template literal:
`HH:MM${myValue? '' : ', XXX'}${anotherValue} - `
I want to replace the hyphen at the end (-
) with en dash (–
) by using its code –
.
I tried several methods but none of them worked. For example:
`HH:MM${myValue? '' : ', XXX'}${anotherValue} – `
and
`HH:MM${myValue? '' : ', XXX'}${anotherValue} + '–'`
Any ideas how to do this?
Having this template literal:
`HH:MM${myValue? '' : ', XXX'}${anotherValue} - `
I want to replace the hyphen at the end (-
) with en dash (–
) by using its code –
.
I tried several methods but none of them worked. For example:
`HH:MM${myValue? '' : ', XXX'}${anotherValue} – `
and
`HH:MM${myValue? '' : ', XXX'}${anotherValue} + '–'`
Any ideas how to do this?
Share Improve this question edited Jul 3, 2022 at 16:27 Daniel Widdis 9,14013 gold badges48 silver badges68 bronze badges asked Jun 25, 2018 at 13:15 Leo MessiLeo Messi 6,19622 gold badges79 silver badges154 bronze badges 5-
have you tried
HH:MM${myValue? '' : ', XXX'}${anotherValue} –
? – Tanmay Commented Jun 25, 2018 at 13:20 -
Some clarifying questions: Why can't you just replace the
-
with a–
? Why are you using–
? What do you mean is doesn't "work"? – James Kraus Commented Jun 25, 2018 at 13:21 - I know that it works like that but I need to do it without using that method – Leo Messi Commented Jun 25, 2018 at 13:28
- 2 You'll need to add more information about what you're trying to do and why that doesn't work. – James Kraus Commented Jun 25, 2018 at 13:37
- @JamesKraus There could be many different reasons why someone needs to use an html entity – Ringo Commented Oct 13, 2020 at 4:22
1 Answer
Reset to default 10You can't use html entities in a template literal. But you can use the unicode equivalent of the –
:
`HH:MM${myValue? '' : ', XXX'}${anotherValue} \u2013 `
See here: https://www.fileformat.info/info/unicode/char/2013/index.htm
本文标签: javascriptUsing HTML entities like ampndash or ampmdash with template literalsStack Overflow
版权声明:本文标题:javascript - Using HTML entities like – or — with template literals - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741826392a2399668.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论