具有不间断空格的呈现字符串
16lz
2021-01-22
I have some props that has a string that could contain characters such as &. It also contains spaces. I want to replace all spaces with
.
我有一些带有字符串的道具,可以包含&之类的字符。它还包含空格。我想把所有的空格都换成空格。
Is there an easy way I can do this? Bear in mind that I cannot just render using this syntax:
有简单的方法吗?请记住,我不能仅仅使用这种语法进行渲染:
<div dangerouslySetInnerHTML={{__html: myValue}} />
because I would first have to replace any HTML entities with their markup. I don't want to have to do this, it seems too low level.
因为我首先必须用它们的标记替换任何HTML实体。我不想这么做,看起来太低了。
Is there a way I can do this?
有办法吗?
4 个解决方案
#1
157
Instead of using the
HTML entity, you can simply use the Unicode non-breaking space character:
而不是使用HTML实体,只需使用Unicode不间断空格字符:
<div>{myValue.replace(/ /g, "\u00a0")}</div>
更多相关文章
- HTML H5之ASCII 代码转义字符集实体编号
- js去掉html标签和去掉字符串文本的所有的空格
- java+空格怎么表示,我想实现一段Java字符在html中20个连续空格
- 关于使用js/jquery监听input框输入的银行卡号,在输入时放大显示且
- 无法从Ajax POST请求中将带空格的数据导入数据库
- PHP用空格分割文本为数组的方法
- 使用没有实体类的本机SQL查询
- 【动软.Net代码生成器】连接MySQL生成C#的POCO实体类(Model)
- 主义通过扩展来破坏对实体的查询