question

RobinJ-0104 avatar image
0 Votes"
RobinJ-0104 asked BingxuanXie edited

Check only one line of the string

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.";
                 }
dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

WayneAKing-0228 avatar image
0 Votes"
WayneAKing-0228 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.