我如何填写这些数字? [英] How do I fill in these numbers?

查看:58
本文介绍了我如何填写这些数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在每个数字上都返回false,所以当我输入hello 1或hello 2或hello 1234567890等时,它会返回false



我尝试过:



i want to return false on each of this numbers, so when i type down hello 1 or hello 2 or hello 1234567890 etc. it return false

What I have tried:

public bool Aliasnaamcontrole(string Alias)
        {
  
            if (Alias.Contains("1234567890"))
            {
                return false;
            }

推荐答案

您可以使用正则表达式:使用System.Text.RegularExpressions添加; 到您的代码文件的顶部,并在您的方法中:

You could use a regular expression: add using System.Text.RegularExpressions; to the top of your code file, and in your method:
if (Regex.IsMatch(Alias, "[0-9]"))
{
    return false;
}



[0-9] 正则表达式 [ ^ ]表示从0到9的数字 。 Regex.IsMatch检查别名是否匹配,如果匹配,则返回false。因此,它将为hello 1,hello 2,hello 12345以及包含数字的所有其他内容返回false。


[0-9] is a regular expression[^] that means "a number from 0 to 9". Regex.IsMatch checks if 'Alias' matches that and if it does, your method returns false. So, it will return false for "hello 1", "hello 2", "hello 12345" and everything else that contains a number.


这篇关于我如何填写这些数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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