可以使用正则表达式来判断字符串是否以数字开头。以下是一个示例代码:

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        string input = "123abc";
        bool startsWithNumber = Regex.IsMatch(input, @"^\d");

        Console.WriteLine(startsWithNumber);  // 输出 True
    }
}

在上述代码中,我们使用 Regex.IsMatch 方法来判断字符串 input 是否以数字开头。正则表达式 @"^\d" 表示以数字开头的模式。如果字符串以数字开头,则返回 True,否则返回 False

C# 判断字符串是否以数字开头

原文地址: https://www.cveoy.top/t/topic/h1MA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录