可以使用Split方法将字符串按照逗号分割为一个字符串数组,然后使用LINQ查询语句筛选以"LX"开头的字符串。以下是示例代码:

using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string input = "LX123, ABC, LX456, DEF, LX789";
        string[] splitStrings = input.Split(',');

        var filteredStrings = splitStrings
            .Select(s => s.Trim()) // 去除字符串前后的空格
            .Where(s => s.StartsWith("LX")); // 筛选以"LX"开头的字符串

        foreach (string str in filteredStrings)
        {
            Console.WriteLine(str);
        }
    }
}

运行结果:

LX123
LX456
LX789
``
C# 将字符串以逗号分割 并筛选出以LX开头的字符串

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

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