Check only one line of the string

RobinJ 276 Reputation points
2020-11-24T10:11:00.19+00:00

Hi,
is it possible to check if only one line of the stringbuilder matches to another string?

//Server Token Datei lesen
                string server_token_string;

                using (StreamReader sr = new StreamReader(@$"{localappdata}\Liquid Aqua\API\server_token.txt", Encoding.Default))
                {
                    StringBuilder server_tokens = new StringBuilder();

                    // schreibt Zeile für Zeile auf den StringBuilder bis das Ende der Datei erreicht ist
                    while (!sr.EndOfStream)
                        server_tokens.AppendLine(sr.ReadLine()); fortschritt_label.Content = "Reading Server File..."; progress_bar.Value = 6;
                    server_token_string = server_tokens.ToString();
                }


                //Überprüfung Token
                if (server_token_string == token_eingabe)
                {
                    title_label.Content = "Gültiger API-Token. Viel Spass mit Liquid Aqua"; fortschritt_label.Content = "API-Check successful finished."; progress_bar.Value = 8;
                    Environment.Exit(0);
                }
                else
                {
                    //Ungültiger Token
                    title_label.Content = @$"Ungültiger Token {token_eingabe}. Bitte erneut versuchen."; progress_bar.Value = 0; fortschritt_label.Content = $"Ungültiger Token {token_eingabe}. Bitte erneut versuchen.";
                }
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,291 questions
0 comments No comments
{count} votes

Accepted answer
  1. WayneAKing 4,921 Reputation points
    2020-11-25T04:23:46.057+00:00

    It isn't clear (to me) exactly what you want to check.

    Do you want to check if one specific line within the StringBuilder object,
    or the string created from it using ToString(), matches another string?

    Or do you want to check if any line in the string (or SB) matches
    another string?

    If the latter, you can use the Contains() method on the string created from
    the SB. e.g. -

    server_token_string = server_tokens.ToString();
    
    //if (server_token_string == token_eingabe)
    
    if (server_token_string.Contains(token_eingabe))
    
    • Wayne
    0 comments No comments

0 additional answers

Sort by: Most helpful