Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 添加增量字母&;数字字符到字符串_C# - Fatal编程技术网

C# 添加增量字母&;数字字符到字符串

C# 添加增量字母&;数字字符到字符串,c#,C#,我需要一个向字符串添加后缀的方法(或2?) 假设我有字符串“你好” 如果我单击选项1,它应该创建一个字符串列表,例如 你好,a 你好,b 你好,c 我已经把那部分搞定了 下一个选项我需要它来创建一个列表,比如 你好,aa 你好,ab 你好,ac ... 你好,巴 你好,bb 你好,bc 等等 此外,每个选项还有2个其他选项 假设我想添加后缀1作为a-z,后缀2作为0-9 那就是 你好,a0 你好,a1 有人能帮我吗?这是我如何做一个字母增量 if (ChkSuffix.Checked)

我需要一个向字符串添加后缀的方法(或2?)

假设我有字符串“你好”

如果我单击选项1,它应该创建一个字符串列表,例如

你好,a 你好,b 你好,c

我已经把那部分搞定了

下一个选项我需要它来创建一个列表,比如

你好,aa 你好,ab 你好,ac ... 你好,巴 你好,bb 你好,bc 等等

此外,每个选项还有2个其他选项

假设我想添加后缀1作为a-z,后缀2作为0-9 那就是

你好,a0 你好,a1

有人能帮我吗?这是我如何做一个字母增量

  if (ChkSuffix.Checked)
            {
                if (CmbSuffixSingle.Text == @"a - z" && CmbSuffixDouble.Text == "")
                {
                    var p = 'a';

                    for (var i = 0; i <= 25; i++)
                    {
                        var keyword = TxtKeyword.Text + " " + p;
                        terms.Add(keyword);
                        p++;
                        //Console.WriteLine(keyword);
                    }
                }
            }
if(ChkSuffix.Checked)
{
如果(CmbSuffixSingle.Text=@“a-z”和&CmbSuffixDouble.Text==”)
{
var p='a';

对于(var i=0;i尝试使用以下扩展方法:

public static IEnumerable<string> AppendSuffix(
    this string @this, string dictionary)
{
    return dictionary.Select(x => @this + x);
}

public static IEnumerable<string> AppendSuffix(
    this string @this, string dictionary, int levels)
{
    var r = @this.AppendSuffix(dictionary);
    if (levels > 1)
    {
        r = r.SelectMany(x => x.AppendSuffix(dictionary, levels - 1));
    }
    return r;
}

public static IEnumerable<string> AppendSuffix(
    this IEnumerable<string> @this, string dictionary)
{
    return @this.SelectMany(x => x.AppendSuffix(dictionary));
}

public static IEnumerable<string> AppendSuffix(
    this IEnumerable<string> @this, string dictionary, int levels)
{
    var r = @this.AppendSuffix(dictionary);
    if (levels > 1)
    {
        r = r.SelectMany(x => x.AppendSuffix(dictionary, levels - 1));
    }
    return r;
}

这听起来像是一个,你能解释一下你想做什么吗?这个类似问题的答案可能会对你有所帮助。我有一个术语(字符串)需要在末尾添加后缀。a-z或0-9…或者两者都按顺序…string+a-z或string+0-9或string+0-9+a-z或string+a-z+0-9
"Hello ".AppendSuffix("abc"); // Hello a, Hello b, Hello c
"Hello ".AppendSuffix("abc", 2); // Hello aa to Hello cc
"Hello "
    .AppendSuffix("abc")
    .AppendSuffix("0123456789"); // Hello a0 to Hello c9