可以使用正则表达式来找到字符串中所有形同 "xxx.dll" 的子字符串。

以下是一个示例代码:

using System;
using System.Text.RegularExpressions;

public class Program
{
    public static void Main(string[] args)
    {
        string input = "This is a test string with abc.dll, def.dll, and xyz.dll.";

        // 使用正则表达式匹配字符串中的 "xxx.dll" 格式
        Regex regex = new Regex(@"\w+\.dll");
        MatchCollection matches = regex.Matches(input);

        // 输出匹配到的子字符串
        foreach (Match match in matches)
        {
            Console.WriteLine(match.Value);
        }
    }
}

上述代码中,我们使用了正则表达式 \w+\.dll 来匹配字符串中的 "xxx.dll" 格式,其中 \w+ 表示匹配一个或多个字母、数字或下划线,\. 表示匹配一个点号。然后,我们使用 MatchCollection 对象来存储所有匹配到的子字符串,并通过遍历输出每个匹配到的子字符串。

运行上述代码,输出结果为:

abc.dll
def.dll
xyz.dll

注意:上述代码只能找到第一个匹配的子字符串,如果要找到所有匹配的子字符串,可以使用 Regex.Matches 方法来获取一个 MatchCollection 对象,然后遍历输出每个匹配到的子字符串

c# 找到一个字符串中所有形同 xxxdll 的子字符串xxx为任意内容

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

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