现在的位置: 首页 > 综合 > 正文

RegEx Tpis

2014年03月17日 ⁄ 综合 ⁄ 共 679字 ⁄ 字号 评论关闭
//z 2012-4-26 16:07:29 PM IS2120@CSDN
1. 正则表达式,匹配(字母,数字,子母和数字)
Only letters:
Regex.IsMatch(input, @"^[a-zA-Z]+$");

Only letters and numbers:
Regex.IsMatch(input, @"^[a-zA-Z0-9]+$");

Only letters, numbers and underscore:
Regex.IsMatch(input, @"^[a-zA-Z0-9_]+$");

bool IsEnglishLetter(char c)
{
    return (c>='A' && c<='Z') || (c>='a' && c<='z');
}

You can make this an extension method:
static bool IsEnglishLetter(this char c) ...

You can use Char.IsLetter(c) && c < 128 . Or just c < 128 by itself, that seems to match 
your problem the closest.

But you are solving an Encoding issue by filtering chars. Do investigate what that other 
application understands exactly.

It could be that you should just be writing with Encoding.GetEncoding(someCodePage)
//z 2012-4-26 16:12:31 PM IS2120@CSDN

抱歉!评论已关闭.