c#字符串内的递增数

问题描述 投票:-2回答:1

我需要打印从001到100的所有电子邮件。例如,[email protected]直到[email protected]我正在尝试使用正则表达式,我将需要递增1的数字分开,但是我不知道如何构造for循环。

    string email = "[email protected]";

        Regex regex = new Regex(@"\d+");  
        var parts = email.Split('@');
        string prefix = Regex.Replace(email, @"\d+", "");
c# regex string increment
1个回答
0
投票

您实际上可以在不使用正则表达式的情况下进行操作,将数字从1循环到100,然后使用string interpolation将数字添加到电子邮件模板中>]

for (int i = 1; i <= 100; i++)
{
    var email = $"test+{i:000}@gmail.com";
    Console.WriteLine(email);
}
© www.soinside.com 2019 - 2024. All rights reserved.