Is it possible to search for a term within a string and output the result either 1 (True) or 0 (false)?

e.g;

string str = 1234567890

if (str.contains = "456")
{
    MessageBox.Show("True!")
}
else
{
    MessageBox.Show("False!")
}

I know I can search for individual chars but I want to be able to match a string and so I don't get a false positive.

thanks in advance!

Recommended Answers

All 2 Replies

The "Contains" method might be what you're looking for:

string str = "1234567890";

if (str.Contains("456"))
{
    MessageBox.Show("True!");
}
else
{
    MessageBox.Show("False!");
}

LOL!

Yup, my pseudo code was almost the same syntax as C#.....

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.