如何在 C# 中编写比较日语字符串的代码?
我们有一个 Excel 文件,其中以日语设置了“公司”文档属性,并且我们有读取“公司”文档属性并将其存储为字符串的代码。
但是,我们不知道如何将其与参考/基准日语字符串进行比较以查看其是否匹配。
请教两个问题:
1)需要什么代码来进行此比较?
现在,我在这里使用字符串比较器解决方案: 将字符串与非英语字符进行比较?
var swedishComparer = StringComparer.Create(new CultureInfo("sv-Se"), true);
consultants = consultants.Where(x => x.Description.Contains(vm.Description, swedishComparer)).ToList();
2) 我将如何存储引用/基准日文字符串?
也就是说,我应该在这里使用“ReferenceStringIn Japanese”:
japaneseComparer.Compare(companyName, 'ReferenceStringInJapanese') == 0
We have an Excel file with the 'Company' document property set in Japanese, and we have code that reads the 'Company' document property and stores it as a string.
However, we do not know how to compare it against a reference/benchmark Japanese string to see if it matches.
Two questions, please:
1) What code is needed to do this comparison?
Right now, I'm using the String Comparer solution here:
Compare strings with non-English characters?
var swedishComparer = StringComparer.Create(new CultureInfo("sv-Se"), true);
consultants = consultants.Where(x => x.Description.Contains(vm.Description, swedishComparer)).ToList();
2) How would I store the reference/benchmark Japanese string?
That is, what should I use for 'ReferenceStringInJapanese' here:
japaneseComparer.Compare(companyName, 'ReferenceStringInJapanese') == 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要比较两个字符串,您可以使用 StringComparer,正如您已经发现的那样。将其与用于日语输入的 ja-JP CultureInfo 一起使用:
可以将要比较的字符串简单地放置在源代码中。 C# 支持 Unicode。
To compare the two strings, you can use a StringComparer, as you already discovered. Use it with a ja-JP CultureInfo for Japanese input:
The string to compare against can simply be placed in your source code. C# supports Unicode.
Visual Studio 编辑器支持 Unicode,因此您应该能够将日语文本字符串直接粘贴到编辑器中。
The Visual Studio editor supports Unicode, so you should be able to paste strings of Japanese text directly into the editor.