标签: non-breaking-characters

JavaScript:用普通空格替换不间断空格和特殊空格字符

我试图调试在字符串内搜索的问题,它归结为以下有趣的代码片段。

\n\n

两者"item ""item "看起来相等,但事实并非如此!

\n\n

\r\n
\r\n
var result = ("item\xc2\xa0" === "item ");\r\n\r\ndocument.write(result);\r\nconsole.log(result);
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n\n

通过将其粘贴到 Python 解释器上进一步研究后,我发现第一个"item "有不同类型的空格,如"item\\xc2\\xa0". 我认为这是一个不间断的空间

\n\n

现在,匹配这些字符串的一个可能的解决方案是用\\xc2\\xa0空格替换,但是是否有更好的方法将所有特殊空格字符转换为普通空格?

\n

javascript string ascii non-breaking-characters

8
推荐指数
2
解决办法
2494
查看次数

如何使测试库的 getByText() 匹配包含不间断空格 ( ) 的字符串?

我正在尝试匹配包含不间断空格的电话号码字符串:

assert
   .dom(
      screen.getByText(
         [my text with a non-breaking space]
      ) as HTMLElement
   )
.exists();
Run Code Online (Sandbox Code Playgroud)

但是,它返回此错误:

Unable to find an element with the text: [my text with a non-breaking space]. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

我该如何测试这个?

non-breaking-characters testing-library

4
推荐指数
1
解决办法
5568
查看次数

PHP:如何摆脱像“\u00a0”这样的奇怪字符?

我有一堆乱七八糟的 JSON 数据要导入到我的数据库中(用于进一步目的)。当我检查它们(在文本编辑器中打开)时,它们包含许多奇怪(胡言乱语)的字符,例如:

  • \u00a0

例如data.json

[{"title":"hello world!","html_body":"<p>Hello\u00a0 from the\u00a0  other side.\u00a0 <\/p>"}]
Run Code Online (Sandbox Code Playgroud)

然后,显然,下面的代码根本行不通:

$clean = str_replace("\u00a0", "", $string);
Run Code Online (Sandbox Code Playgroud)

不管这些角色是干什么用的,我怎么能摆脱它们呢?

php special-characters hidden-characters non-breaking-characters

1
推荐指数
1
解决办法
4380
查看次数

如何从 Postgres 中的列中删除不间断空格

试图从一个字段中删除一个不间断的空间,但没有任何成功。我试过了

execute <<-SQL
  UPDATE customers
  SET name = TRIM (name)
SQL
Run Code Online (Sandbox Code Playgroud)

但这只会删除空格。这是与this类似的问题,但我需要它用于Postgres(Postgres抱怨syntax error at or near "x00A0")并且我只需要修剪即它必须仅在文本的开头和结尾删除。

谢谢

postgresql trim non-breaking-characters

1
推荐指数
1
解决办法
1655
查看次数