473,480 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with .Contains

Hi,

My form is - a listbox which contains 5 items, a textbox and a button.

ListBox - subjectListBox
TextBox - subjectTextBox
When the button is clicked, I want the 5 items in the listbox to be
compared to the text in the textbox (note: items in listbox are single
words - text in textbox can be many words) - and if any of the items in
the textbox match the an item in the list box, I want a message to
appear.

The error message I keep getting is: 'string' does not contain a
definition for 'Contains'

Here is the code I am trying to use within the button:

int counter;
int flag=0;

for (counter = 0; counter < 5; counter++){
if
(subjectTextBox.Text.Contains(subjectListBox.Items[counter].ToString()))
flag=1;
}
if (flag==1)
MessageBox.Show(strMessage);

I have emailed someone else who tested this code - and it worked for
them!
When this happend, I started a new project, and tried it again from
fresh - still not working.
Possibly a problem with my VSC#2003 insallation?

Any help would be greatly appreciated.

Apr 7 '06 #1
5 1333
> I have emailed someone else who tested this code - and it worked for them!

With all due respect... no it didn't. The compiler is telling you the
truth: the String type does not have a method called "Contains". You
probably want this instead:

boolean found=false;

for (counter = 0; counter < 5 && !found; counter++)
{
if
(subjectTextBox.Text.IndexOf(subjectListBox.Items[counter].ToString())
= 0)

found=true;
}
if (found) MessageBox.Show(strMessage);

Apr 7 '06 #2
Sorry, that should have been:

bool found = false;

Apr 7 '06 #3
Sorry, that should have been:

bool found = false;

Apr 7 '06 #4
Bruce Wood wrote:
I have emailed someone else who tested this code - and it worked for them!


With all due respect... no it didn't. The compiler is telling you the
truth: the String type does not have a method called "Contains". You
probably want this instead:

..net 2.0 (Visual Studio 2005) added a String.Contains method. It's
basically a neater way of saying String.IndexOf() >= 0.
Apr 7 '06 #5
Ahh. The evils of answering before asking which version the OP is
running. :-)

So, evidently the OP is running 1.1 (as I am) and the other person was
running 2.0.

Thanks, David. I learn something new every day here. :-)

Apr 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4446
by: rufpirat | last post by:
Hello I'm in the middle of trying to build an "AD phone book", and this being my first try at asp.net, I have a few questions that I hope some of you might be able to help with: 1. Is it...
53
4594
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
10
1891
by: pmarisole | last post by:
This is the first page...... <select size="1" name="Q1_<%=i%>" onChange="calc(<%=i%>)"> <option selected value="<% =rsScores("Q1") <option value="1">1</option> <option value="2">2</option>...
8
1355
by: Tanzen | last post by:
I'm working in visual studio 2005 trying to learn visual basic. Having come from an VB for Access background, I'm finding it a big learning curve. I have been working through several e-books which...
2
9995
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.