| | |
how to find a word in c#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 55
Reputation:
Solved Threads: 0
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
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.
•
•
Join Date: Feb 2009
Posts: 55
Reputation:
Solved Threads: 0
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.";
}
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.";
}
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.
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
Make love, no war. Cave ab homine unius libri.
Danny
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).
•
•
Join Date: Mar 2008
Posts: 324
Reputation:
Solved Threads: 7
C# Syntax (Toggle Plain Text)
private void Form1_Load(object sender, EventArgs e) { string sText="Sonia Sardana"; if (sText.Contains("Sonia")) { MessageBox.Show ("contains"); } }
•
•
Join Date: Feb 2009
Posts: 55
Reputation:
Solved Threads: 0
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.";
}
}
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.";
}
}
•
•
Join Date: Feb 2009
Posts: 55
Reputation:
Solved Threads: 0
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.";
}
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.";
}
![]() |
Similar Threads
- Word Association Game (Posting Games)
- c++ find word from text file (C++)
- Error trying to perform single word searches in address bar. (Viruses, Spyware and other Nasties)
- Find word in file!! (C++)
- simple code to find a word in any page (Python)
- find strings in file.txt (C++)
- Scan text file to find all words of 4 characters or less (Shell Scripting)
Other Threads in the C# Forum
- Previous Thread: I need .NET basic interview questions urgently
- Next Thread: Media Converter
| Thread Tools | Search this Thread |
.net access algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client combobox control conversion csharp custom database databasesearch datagrid datagridview datagridviewcheckbox dataset datetime degrees development draganddrop drawing dynamiccreation encryption enum equation event excel file form format formatting forms function gdi+ hospitalmanagementsystems httpwebrequest image index input install interface java label list listbox mandelbrot math mouseclick mysql namevaluepairs operator path photoshop picturebox pixelinversion post powerpacks programming property radians regex remote remoting resource restore richtextbox server sleep soap socket sql statistics stream string table text textbox thread time timer update usercontrol validation visualstudio wait webbrowser windows winforms working wpf xml






