如果没有Regex,我怎么能这样做? [英] How can I do this without Regex ?

查看:68
本文介绍了如果没有Regex,我怎么能这样做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有办法写一个更快的函数?

public static bool IsNumber(char Value)

{

if(Regex.IsMatch(Value.ToString(),@" ^ [0-9] + $"))

{

返回true;

}

否则返回false;

}


我想,如果我必须重复这个数千次,它可能会非常耗时。


提前谢谢,


PS

C#中是否存在与Delphi相似的内容?


Is there a way to write a faster function ?

public static bool IsNumber( char Value )
{
if (Regex.IsMatch( Value.ToString(), @"^[0-9]+$" ))
{
return true;
}
else return false;
}

I think, if I have to repat this some thousands time, it
could become very time consuming.

Thanks in advance,

P.S.
Is there in C# something similar to Delphi''s sets ?

推荐答案

" ))

{

返回true;

}

否则返回false;

}


我想,如果我必须重复这几千次,那么
可能会变得非常耗时。


提前致谢,


PS

C#中是否有与Delphi相似的东西?

" ))
{
return true;
}
else return false;
}

I think, if I have to repat this some thousands time, it
could become very time consuming.

Thanks in advance,

P.S.
Is there in C# something similar to Delphi''s sets ?


Tim Conner< Ti ******* @ discussion.microsoft.com>写道:
Tim Conner <Ti*******@discussions.microsoft.com> wrote:
有没有办法写一个更快的函数?

公共静态bool IsNumber(char值)
{/ if if(Regex.IsMatch) (Value.ToString(),@" ^ [0-9] +
Is there a way to write a faster function ?

public static bool IsNumber( char Value )
{
if (Regex.IsMatch( Value.ToString(), @"^[0-9]+


"))
{
返回true;
}
否则返回false;
}
我认为,如果我必须重复这几千次,它可能会变得非常耗时。
" ))
{
return true;
}
else return false;
}

I think, if I have to repat this some thousands time, it
could become very time consuming.




虽然正则表达式非常强大,但它们并不是非常快速地执行简单的操作 - 而且你为每个调用创建一个新的字符串

好​​吧。更简单,更快捷的是:


public static bool IsNumber(char value)

{

return(value> ='' 0''&& value< ='''9'');

}


-

Jon Skeet - < sk *** @ pobox.com>
http:// www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



While regular expressions are very powerful, they''re not very fast for
doing simple thing - and you''re creating a new string for each call as
well. Far simpler and faster is:

public static bool IsNumber (char value)
{
return (value>=''0'' && value <=''9'');
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于如果没有Regex,我怎么能这样做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆