string[] get specific username from String Array

i was following Dreamlo Tutorial

in Void FormatHighscores

void FormatHighscores(string textStream) {
        string[] entries = textStream.Split(new char[] {'\n'}, System.StringSplitOptions.RemoveEmptyEntries);
        highscoresList = new Highscore[entries.Length];
       
        for (int i = 0; i <entries.Length; i ++) {
            string[] entryInfo = entries[i].Split(new char[] {'|'});
            string username = entryInfo[0];
            int score = int.Parse(entryInfo[1]);
            highscoresList[i] = new Highscore(username,score);
        }
    }

i put print (highscoresList[i].username + ": " + highscoresList[i].score);

its print all users on the leaderboard, but how do i print specific name from the array

thanks.

:stuck_out_tongue:

Lol

@heipp123_1 What you’re asking is probably a different function than the code you posted. I guess you could do it by comparing the username to a specific string, and only printing it if they match, but there’s probably a better way.

The code that you added is doing exactly what it’s supposed to be doing, though, so it’s working properly.

Sorry i am really bad explaining. i was trying to check if my player Name is on the list and If its it would print my name and my score.

Thanks

Nah, you’re good. I understood exactly what you were going for. I may not have done a good enough job explaining how to approach your goal.

Not to offend you, but do you understand what the code that you posted does? If not, and you want to continue developing games, it’s pretty important to learn. Thankfully, Unity provides a great tutorial series to get started.

If you’re not into learning and just want to do this and be done with it, modify the code you had posted to this:

void GetAndPrintPlayerScore(string textStream, string playerName) {
  string[] entries = textStream.Split(new char[] {'\n'}, System.StringSplitOptions.RemoveEmptyEntries);
  for (int i = 0; i < entries.Length; i ++) {
    string[] entryInfo = entries[i].Split(new char[] {'|'});
    string username = entryInfo[0];

    if (username == playerName) {
        int score = int.Parse(entryInfo[1]);
        print(username + ": " + score);
        return;
      }
  }
}

And call it like

GetAndPrintPlayerScore("_WHATEVER_WAS_ALREADY_HERE_", "Bozo the Clown");

Thanks