-1

我制作这个应用程序是为了好玩,但我有一个问题

我希望在单独的行中读取此字符串/文件。

这是文件(不是整个文件):

1ChampSelectPack.Ahri.mp31ChampSelectPack.Akali.mp31ChampSelectPack.Alistar.mp31ChampSelectPack.Amumu.mp31ChampSelectPack.Anivia.mp31ChampSelectPack.Annie.mp31ChampSelectPack.Ashe.mp31ChampSelectPack.Blitzcrank.mp31ChampSelectPack.Brand.mp31ChampSelectPack.Caitlyn.mp3

这就是我到目前为止得到的:

            List<SoundPath> paths = new List<SoundPath>();
            StreamReader reader = File.OpenText("C:/Users/Esat/Documents/Visual Studio 2010/Projects/WikiLoL/WikiLoL/lolSoundBoard/1ChampSelectPack/files.txt");

            while (!reader.EndOfStream)
            {

                SoundPath path = new SoundPath();
                path.Path = reader.ReadLine();
                paths.Add(path);
            }

            reader.Close();

            return paths;
4

2 回答 2

2

不确定这是否是您想要的:

"YourString".Split(new string[] {"mp3"}, StringSplitOptions.None)

之后您必须在每一行附加“mp3”。

于 2012-10-10T11:11:35.327 回答
1

您可以使用拆分 .mp3 并在结果数组的每个元素中添加 .mp3 来做到这一点。

string text = File.ReadAllText("C:/Users/Esat/Documents/Visual Studio 2010/Projects/WikiLoL/WikiLoL/lolSoundBoard/1ChampSelectPack/files.txt");
string[] lines = text.Split(new string[] { ".mp3" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < lines.Length; i++)
    lines[i] = lines[i] + ".mp3";
于 2012-10-10T10:23:27.390 回答