欢迎访问我的博客 https://javascript.shop

Replacing Accented characters(Diacritic) .NET

原文发布时间为:2012-02-17 —— 来源于本人的百度文章 [由搬家工具导入]

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using  System.Globalization;

 static string RemoveDiacritics(string stIn) {
  string stFormD = stIn.Normalize(NormalizationForm.FormD);
  StringBuilder sb = new StringBuilder();

  for(int ich = 0; ich < stFormD.Length; ich++) {
    UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);
    if(uc != UnicodeCategory.NonSpacingMark) {
      sb.Append(stFormD[ich]);
    }
  }
  return(sb.ToString().Normalize(NormalizationForm.FormC));

posted @ 2017-07-15 14:20  孑孓子  阅读(162)  评论(0编辑  收藏  举报
欢迎访问我的博客 https://javascript.shop