C# 将字符串中以逗号隔开的字母开头的字符串分割出来
您可以使用Split()方法将字符串按照逗号进行分割,然后使用LINQ查询筛选出以字母开头的字符串。以下是一个示例代码:
using System;
using System.Linq;
class Program
{
static void Main(string[] args)
{
string input = "A,BC,123,DEF,GHI,JKL,456";
// 使用Split()方法按逗号进行分割
string[] splitted = input.Split(',');
// 使用LINQ查询筛选出以字母开头的字符串
var result = splitted.Where(s => char.IsLetter(s[0]));
// 输出结果
foreach (string str in result)
{
Console.WriteLine(str);
}
}
}
以上代码会输出:
A
BC
DEF
GHI
JKL
``
原文地址: http://www.cveoy.top/t/topic/h1ly 著作权归作者所有。请勿转载和采集!