string filter: detect non-ASCII signs

前端 未结 3 971
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 01:04

I am creating an application which will send the input string to mobile device. Some devices have problems with encoding special characters so I would like to create a filte

3条回答
  •  心在旅途
    2021-01-14 01:40

    Well you can do:

    public static bool IsAllAscii(string text)
    {
        return text.All(c => c >= ' ' && c <= '~');
    }
    

    I'm not sure you would really want to just remove the last character entered though - consider cutting and pasting a whole non-ascii string...

提交回复
热议问题