在 C# 中删除复合 Unicode 字符

Remove composite Unicode characters in C#

我们在日志中收到有关查询的错误,例如:

SELECT display_term FROM SYS.DM_FTS_PARSER('FORMSOF(INFLECTIONAL, 文看得刺眼(主要是事件表内的显示)将它截图反馈给我们)', 1033, 0, 0) AS DM_FTS_PARSER_1

我们发现它是特殊的 Unicode 字符:

请注意,这些不是普通的圆括号,它们似乎是一个 space 和一个字符中的括号,是某种复合 Unicode 字符。

过滤掉复合 Unicode 字符或将它们分解成复合部分的最佳方法是什么?

documentation 看来,如果数据库的默认排序规则不是 unicode,您似乎应该将查询字符串作为 unicode 传递:

When you parse a query string, sys.dm_fts_parser uses the collation of the database to which you are connected, unless you specify the query string as Unicode. Therefore, for a non-Unicode string that contains special characters, such as ü or ç, the output might be unexpected, depending on the collation of the database. To process a query string independently of the database collation, prefix the string with N, that is, N'query_string'.

因此,我建议将您的查询更改为:

SELECT display_term FROM SYS.DM_FTS_PARSER(N'FORMSOF(INFLECTIONAL, 文看得刺眼(主要是事件表内的显示)将它截图反馈给我们)', 1033, 0, 0) AS DM_FTS_PARSER_1