我试图调试在字符串内搜索的问题,它归结为以下有趣的代码片段。
\n\n两者"item "和"item "看起来相等,但事实并非如此!
var result = ("item\xc2\xa0" === "item ");\r\n\r\ndocument.write(result);\r\nconsole.log(result);Run Code Online (Sandbox Code Playgroud)\r\n通过将其粘贴到 Python 解释器上进一步研究后,我发现第一个"item "有不同类型的空格,如"item\\xc2\\xa0". 我认为这是一个不间断的空间。
现在,匹配这些字符串的一个可能的解决方案是用\\xc2\\xa0空格替换,但是是否有更好的方法将所有特殊空格字符转换为普通空格?
我正在尝试匹配包含不间断空格的电话号码字符串:
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.
我该如何测试这个?
我有一堆乱七八糟的 JSON 数据要导入到我的数据库中(用于进一步目的)。当我检查它们(在文本编辑器中打开)时,它们包含许多奇怪(胡言乱语)的字符,例如:
例如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
试图从一个字段中删除一个不间断的空间,但没有任何成功。我试过了
execute <<-SQL
UPDATE customers
SET name = TRIM (name)
SQL
Run Code Online (Sandbox Code Playgroud)
但这只会删除空格。这是与this类似的问题,但我需要它用于Postgres(Postgres抱怨syntax error at or near "x00A0")并且我只需要修剪即它必须仅在文本的开头和结尾删除。
谢谢