0

So this is my current code:

string serverInfo = "Connected to 74.91.119.188:27015\n" +
                            "hostname:[FN] 24 / 7 Surf Utopia | Styles | !KNIFE,!WS,!GLOVES\n" +
                            "version: 1.37.9.5 secure\n" +
                            "os      :  Linux\n" +
                            "type    :  community dedicated\n" +
                            "map: surf_utopia_v3\n" +
                            "players : 24 humans, 0 bots(64 / 0 max)(not hibernating)\n" +

                            "# userid name uniqueid connected ping loss state rate\n" +
                            "# 3785 1 \"Con\" STEAM_1:0:128083116 03:13 32 0 active 196608\n" +
                            "# 3786 2 \"yolo\" STEAM_1:0:172863146 03:13 171 0 active 196608\n" +
                            "# 3787 3 \"chodyツ\" STEAM_1:0:42129452 03:13 46 0 active 786432\n" +
                            "#end\n";
        var removeEnd = serverInfo.IndexOf("#end");
        var newString = serverInfo.Remove(removeEnd);
        var firstHashTag = newString.IndexOf("#");
        var secondHashTag = newString.IndexOf("#", firstHashTag + 1);
        var final = newString.Substring(secondHashTag);

        var newFinal = final.Replace("# ", "#");

        using (StringReader reader = new StringReader(newFinal.ToString()))
        {
            string readText = await reader.ReadToEndAsync();

            int foundS1 = readText.IndexOf(" ");
            int foundS2 = readText.IndexOf(" ", foundS1 + 1);

            newFinal2 = readText.Remove(foundS1 + 1, foundS2 - foundS1);

            Console.WriteLine(newFinal2);
        }
        Console.ReadLine();

Result from code

My question is. How can I modify this portion:

            using (StringReader reader = new StringReader(newFinal.ToString()))
        {
            string readText = await reader.ReadToEndAsync();

            int foundS1 = readText.IndexOf(" ");
            int foundS2 = readText.IndexOf(" ", foundS1 + 1);

            newFinal2 = readText.Remove(foundS1 + 1, foundS2 - foundS1);

            Console.WriteLine(newFinal2);
        }

So that it applies to every line there might be? The string serverInfo is data I've typed myself, but usually I would get this data from the API. Each line represents a player, and I don't know how many there might be, when I eventually get the data from the API, so I need a solution that doesn't know how many lines there will be. So how can I remove something from every line, where the conditions are the same

0

1 Answer 1

1

You can split the lines using the string.Split function:

var userLines = newFinal.Split(Environment.NewLine);
foreach (var userLine in userLines)
{
    Console.WriteLine(userLine);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.