blah blah blah is here! blah blah » Close

up0down
link

hello

i want to check if richtextbox1.text start with "http://www.debugging.com" or not

how can i do that

last answered one year ago

2 answers

link

I don't think Glenn has understood the question properly as you're
asking whether the text in the RichTextBox starts with "http://www.debugging.com" and not just whether it's equal to that string:

// if you don't want to include the double quotes

if (richTextBox1.Text.StartsWith("http://www.debugging.com"))
{
MessageBox.Show("Yes!");
}
else
{
MessageBox.Show("No!");
}

// or, if want to include the double quotes as part of the string

if (richTextBox1.Text.StartsWith("\"http://www.debugging.com\""))
{
MessageBox.Show("Yes!");
}
else
{
MessageBox.Show("No!");
}

GlennP
329

Aha! that would make more sense. Does StartsWith() check the whole string or just the first character? Cool I just had a peak on MSDN for it! Glenn

vulpes
17279

It checks the whole string and, if I remember correctly, there's an overload which allows you to ignore case amongst other things.

up1down
link

Hmm,

Don't really think I understand/asked the question properly but from the way it is asked

richtextbox1.Text == "http://www.debugging.com"


and later on (Change the No! to whatever)
if (richTextBox1.Text != "http://www.debugging.com")
MessageBox.Show("No!");

That will do what you asked for, probably not what you meant!

Glenn

Feedback