开发者

How to get the char count between two indexes in a string?

开发者 https://www.devze.com 2023-02-06 20:02 出处:网络
private IEnumerable<Player> GetGamePlayers(string content, string map) { List<Player> Players = new List<Player>();
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;
}

The positions variabl开发者_如何转开发e holds the start indexes of the sections I need.

So basically, I need a substring from position[0] to position[1] - 1.

Any suggestions?


why don't you use a regular for loop since you need the index:

for (int i = 0; i < positions.Count-1; i++)
{
        string section = content.Substring(positions[i], 
                                           positions[i+1]-positions[i]);
        Players.Add(ParsePlayer(section));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号