locked
How to remove special character from string which can include Asian character? RRS feed

  • Question

  • I can remove special character from string which includes English/Numeric characters like following.

    public static string RemoveSpecialCharacters(string str)
    {
        return Regex.Replace(str, "[^a-zA-Z0-9_.]+", "", RegexOptions.Compiled);
    }

    However this removes non-special characters in case of Asian character.

    How to remove only special character?

    Wednesday, May 6, 2020 4:05 AM

All replies

  • Try this expression:

       @"[^\p{L}\p{N}_.]"

    Wednesday, May 6, 2020 4:28 AM
  • Hi,

    Has your issue been resolved?

    If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 12, 2020 8:21 AM