How to remove certain characters from HTML code using ASP

痞子三分冷 提交于 2019-12-24 09:58:50

问题


Just like the title says, how do I tell the page to output the HTML code and remove certain characters, such as this character (ü)


回答1:


This is a method that removes diacritics:

public static string RemoveDiacritics(this string input)
{
    input = input.Normalize(NormalizationForm.FormD);
    StringBuilder output = new StringBuilder();

    for (int i = 0; i < input.Length; i++)
    {
        if (CharUnicodeInfo.GetUnicodeCategory(input[i]) != UnicodeCategory.NonSpacingMark) 
            output.Append(input[i]);
    }

    return output.ToString();
}

Example usage:

string str = RemoveDiacritics("éïå"); // str = "eia"



回答2:


Do you mean specific enumerated characters, or all characters with diacritics? http://en.wikipedia.org/wiki/Diacritic

 myString = Replace(myString, "ü", "")


来源:https://stackoverflow.com/questions/5545790/how-to-remove-certain-characters-from-html-code-using-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!