how to find a word in c#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2009
Posts: 55
Reputation: tintincute is an unknown quantity at this point 
Solved Threads: 0
tintincute tintincute is offline Offline
Junior Poster in Training

how to find a word in c#

 
0
  #1
Feb 25th, 2009
hi
I'm new to C# and I didn't have any programming skills.
I'm on my third week now and it seems it's quite complex

I would like to design a code, where it can determine the word type in the sentence.
So, first one must type a sentence and then on the second box, just type a word and check if its present in the first box (from the sentence you typed)
the result should show, true or false.

I started a code but I don't know how to continue: Any idea or suggestion is greatly appreciated:

namespace DisplayWordJaNein
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string yourSentence;
string yourWord;

yourSentence = textBox1.Text;
yourWord = textBox2.Text;

if


from here I'm not sure what to do. From what I've learned I have to use the type bool here. But don't know how to implement.


thanks & regards
Last edited by tintincute; Feb 25th, 2009 at 7:56 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 55
Reputation: tintincute is an unknown quantity at this point 
Solved Threads: 0
tintincute tintincute is offline Offline
Junior Poster in Training

Re: how to find a word in c#

 
0
  #2
Feb 25th, 2009
hi again

i was able to finish it until here and it's working. But what I like is, it will display "Word Found" or let's say true if I'll write a word which is on the sentence itself.
ok, I tried to write: this is my first sentence
and on the 2nd box, if i write "sentence" only it displays "the word can't be found".

so i think i'm on the right track but i'd like that it will give me result "true" if the word i type is on the sentence

thanks

here is my code:

namespace DisplayWordJaNein
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string yourSentence;
string yourWord;

yourSentence = textBox1.Text;
yourWord = textBox2.Text;

if (string.Equals(yourSentence,yourWord))
{
label4.Text="Word Found!";
}
else
{
label4.Text="The word could not be found.";
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: how to find a word in c#

 
0
  #3
Feb 25th, 2009
Well, google will perhaps help you in finding things in strings. There are a number of options you could use..
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,941
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 279
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: how to find a word in c#

 
0
  #4
Feb 25th, 2009
Look up the members of the String class.
From the code I see you use some Visual Studio.
In the menubar you will find something called "Help"
Click on it and choose Search. In the window that appears type String members
You will find what you where looking for.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,215
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 573
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: how to find a word in c#

 
0
  #5
Feb 25th, 2009
Take a look at string.Contains() or string.Compare() instead of string.Equals(). You will also need to address the casing of the word (uppercase, lowercase).
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Re: how to find a word in c#

 
0
  #6
Feb 25th, 2009
  1. private void Form1_Load(object sender, EventArgs e)
  2. {
  3. string sText="Sonia Sardana";
  4. if (sText.Contains("Sonia"))
  5. {
  6. MessageBox.Show ("contains");
  7. }
  8. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 55
Reputation: tintincute is an unknown quantity at this point 
Solved Threads: 0
tintincute tintincute is offline Offline
Junior Poster in Training

Re: how to find a word in c#

 
0
  #7
Mar 2nd, 2009
Hi

I was able to find it. But my next problem is: I would like it that it will also accept the UPPERCASE or LOWERCASE letters if I type in the "enter word to compare".

So that means if I write in the first box like:

This is my sentence

And I'll write in my second box like:
SENTENCE,

that it wil also determine that way.
Is that posible?
Coz in my code, I wrote the big letters SENTENCE but then it didn't find the word.
Shall I make another method for that?
Thanks again

namespace DisplayWordJaNein
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string yourSentence;
string yourWord;


yourSentence = textBox1.Text;
yourWord = textBox2.Text;


if (yourSentence.Contains(yourWord))
{
label4.Text = "Word Found! / ";
}
else
{
label4.Text="The word could not be found.";
}
}
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: how to find a word in c#

 
0
  #8
Mar 2nd, 2009
then convert the strings to the same casing and test after.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 55
Reputation: tintincute is an unknown quantity at this point 
Solved Threads: 0
tintincute tintincute is offline Offline
Junior Poster in Training

Re: how to find a word in c#

 
0
  #9
Mar 2nd, 2009
hmm where shall I type this command,
convert strings?
is it under the if method?
thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 55
Reputation: tintincute is an unknown quantity at this point 
Solved Threads: 0
tintincute tintincute is offline Offline
Junior Poster in Training

Re: how to find a word in c#

 
0
  #10
Mar 2nd, 2009
Hi again,

ok I tried this one, but then it displays the word if I write the word. But the bug is if I only write a letter which a word has, it also displays "Word Found"

I would like that it will only determine the word not the characters.

In this program:
if I type on the first box:
This is my sentence

and type on the 2nd box:
sentence

it will give a result of word found

but then if i type in the first box:
s

it will give a result of word found.
any suggestions?

thanks




if (yourSentence.Contains(yourWord.ToLower()))
{

label4.Text = "Word Found! / ";

}
else
{
label4.Text="The word could not be found.";
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC