Как получить количество символов между двумя индексами в строке? - PullRequest
0 голосов
/ 23 января 2011
private IEnumerable<Player> GetGamePlayers(string content, string map)
{
    List<Player> Players = new List<Player>();

    var positions = new List<int>();

    for (int i = 0; i < 5; i++)
    {
        positions.Add(content.IndexOf(String.Format("[{0}] (com.riotgames.platform.gameclient.domain::PlayerParticipantStatsSummary)", i)));
    }

    for (int i = 0; i < 5; i++)
    {
        positions.Add(content.IndexOf(String.Format("[{0}] (com.riotgames.platform.gameclient.domain::PlayerParticipantStatsSummary)", i), positions[4] + 500));
    }

    foreach (var position in positions)
    {
        //NEED HELP HERE!
        var section = content.Substring(position, )
        Players.Add(ParsePlayer(section));
    }

    return Players;
}

Переменная положений содержит начальные индексы нужных мне разделов.

Так что в основном мне нужна подстрока из позиции [0] в позицию [1] - 1.

Есть предложения?

1 Ответ

0 голосов
/ 23 января 2011

почему вы не используете регулярный цикл for, так как вам нужен индекс:

for (int i = 0; i < positions.Count-1; i++)
{
        string section = content.Substring(positions[i], 
                                           positions[i+1]-positions[i]);
        Players.Add(ParsePlayer(section));
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...