mardi 20 juillet 2021

How to only use a line of a string in a richtextbox for an if statement in C#

What im trying to is to make an if statement that only uses a line of a richtextbox OR Make an if statement that uses text and only till it finds a char (example; ";" and ".")

I've tried separating string with ";" like this

string codeline = richtextbox1.Text;
if(codeline.Contains("Say"){
  richtextbox2.Text += codeline.Split(';') + Environment.NewLine;
}

but it does nothing to help with the issue

please help my brain is dying from trying to think of answers

The whole code

if (codeline.Contains("Say"))
{
    string say = "Say";
    foreach (string line in richTextBox1.Lines)
    {
        if(line.Contains(say)) {
            char remove_quotes = '"';
            string quotess = remove_quotes.ToString();
            codeline = codeline.Replace("Say", "");
            if (codeline.Contains(quotess) && codeline.Contains(";"))
            {
                codeline = codeline.Replace(quotess, "");
                codeline = codeline.Replace(";", "");
                richTextBox2.ForeColor = Color.White;
                richTextBox2.Text += "";
                richTextBox2.Text += codeline + Environment.NewLine;
            }
    }
}

The Output I want is: if the user were to type in rtf1 Say"hello; , then it will output "hello" but if I were to type in Say"hello; Say"hello2; it would instead output **hello Say hello2 so yea I'm trying to fix that by removing the "Say" keyword

Aucun commentaire:

Enregistrer un commentaire