List <string> .replace问题

时间:2018-09-21 17:15:50

标签: c#

我制作了一个工具,并且效果很好,由于某种原因,现在我遇到了问题:

line1
line2
line3

line1 line2 line3

在此之前,它像[好示例]一样工作,现在却像[不好的示例]

代码:

string[] temp = File.ReadAllLines(Environment.CurrentDirectory + "/Normal/DorkType.txt");
        foreach (string s in temp)
            DorkType.Add(s);
        // Load the Keywords
        string[] temp1 = File.ReadAllLines(Environment.CurrentDirectory + "/Normal/Keywords.txt");
        foreach (string s in temp)
            Keywords.Add(s);
        // Load the Domains
        string[] temp2 = File.ReadAllLines(Environment.CurrentDirectory + "/Normal/Domains.txt");
        foreach (string s in temp)
            Domains.Add(s);
        // Load the PageType
        string[] temp3 = File.ReadAllLines(Environment.CurrentDirectory + "/Normal/PageType.txt");
        foreach (string s in temp)
            PageType.Add(s);
        // Load the PageFormat
        string[] temp4 = File.ReadAllLines(Environment.CurrentDirectory + "/Normal/PageFormat.txt");
        foreach (string s in temp)
            PageFormat.Add(s);
        // Load the SearchFunctions
        string[] temp5 = File.ReadAllLines(Environment.CurrentDirectory + "/Normal/SearchFunction.txt");
        foreach (string s in temp)
            SearchFunction.Add(s);
        // Load the Type
        string[] temp6 = File.ReadAllLines(Environment.CurrentDirectory + $"/HQmethods/Preset/Preset{Preset}.txt");
        foreach (string s in temp)
            Type.Add(s);
        // Load the Keyword
        string[] temp7 = File.ReadAllLines(Environment.CurrentDirectory + "/HQmethods/Keyword.txt");
        foreach (string s in temp)
            Keyword.Add(s);
        // Load the 2nd Keyword
        string[] temp8 = File.ReadAllLines(Environment.CurrentDirectory + "/HQmethods/Keyword2.txt");
        foreach (string s in temp)
            Keyword2.Add(s);

if (PageFormatType == "None" || PageFormatType == "none")
{
    // if the user choose the None mode
    // Replace 'KW' with the user Keywords
    NewDorks.Add(DorkType[counter]
        .Replace("KW", Keywords[rnd.Next(0, Keywords.Count)])
        .Replace("PT", PageType[rnd.Next(0, PageType.Count)])
        .Replace("PF", PageFormat[rnd.Next(0, PageFormat.Count)])
        .Replace("DE", Domains[rnd.Next(0, Domains.Count)])
        .Replace("SF", SearchFunction[rnd.Next(0, SearchFunction.Count)]));

    counter++;
}

public static void SaveDorks()
{
    using (StreamWriter write = new StreamWriter(Environment.CurrentDirectory + 
        "/Finished.txt"))
    {
        foreach (string s in NewDorks)
            write.WriteLine(s);
        write.Close();
    }
}

这段代码在另一个类中,我在Main类中将其称为

NewDorks-> List<string>

DorkType-> List<string>

假设我有一个文本文件,

1
2
3

而不是将其添加到NewDorks中,输出看起来像这样

1
2
3

输出如下:

1 2 3

0 个答案:

没有答案