简体   繁体   English

c# - 如何比较在c#中具有(á,í,ä)类似字符的两个字符串?

[英]How to compare two strings which having (á,í,ä) like characters in c#?

I need to compare two strings in a word document I work it out for alphabetic and numeric values but it is not able to compare a string which contains some special characters like Máceres-Cartínez(á,í,ä) my code did not consider this occurrence as a string.我需要比较 word 文档中的两个字符串我计算出字母和数字值,但它无法比较包含一些特殊字符的字符串,如 Máceres-Cartínez(á,í,ä) 我的代码没有考虑这一点作为字符串出现。 StreamWriter(fsf); StreamWriter(fsf);

    swt.WriteLine("Startred on :" + DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss") + "\n");

    swf.WriteLine("Startred on :" + DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss") + "\n");


    foreach (string strPara in strParaValue)

      {
          string[] strAuthorsPart = strPara.Split('.');

          string[] strAuthorslist = strAuthorsPart[0].Split(',');

          string[] strAuthor = strAuthorslist[0].Split(' ');

          if (strSplitValue[0].Contains(strAuthor[0].Trim()))

         {

             swt.WriteLine(strAuthor[0] + "\t");

         }

              else

         {

             swf.WriteLine(strAuthor[0] + "\t");

         }

              swt.WriteLine("\r\n");

              swf.Flush();

          }

Please let me suggest on this regards.请让我就这方面提出建议。

DeeGo迪高

If I understood your question correctly, you want to ignore diacritics when comparing two strings, ie "Maceres" should match "Máceres" .如果我正确理解了您的问题,您希望在比较两个字符串时忽略变音符号,即"Maceres"应匹配"Máceres"

If that is correct, the simplest solution is to remove diacritics from both strings and then compare them.如果这是正确的,最简单的解决方案是从两个字符串中删除变音符号,然后比较它们。 The following question contains suggestions on how to do that:以下问题包含有关如何执行此操作的建议:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM