-
March 29th, 2012, 06:13 AM
#16
Re: Need Help with Parser C#
Long time no post!
Thanks for all the help last time, Now I'm just wondering how I'd go about changing this code:
Code:
private void btnTrans_Click(object sender, EventArgs e)
{
string outputString = null;
if (d.TryGetValue(inputBx.Text, out outputString))
{
;
outputBx.Text = outputString;
}
else //Did not find the string
{
outputBx.Text = "Unknown ";
}
}
so that instead of just typing in the one word I could type in something like, "I can't believe it was on" and it would output "I can't believe it was off" On and off being split word 1 and 2.
So I'm not sure how i'd go about writing code so it searches if it contains the string and prints the full thing with the changed word.
Any help guys?
-
March 29th, 2012, 08:15 AM
#17
Re: Need Help with Parser C#
Originally Posted by dahrull
...instead of just typing in the one word I could type in something like, "I can't believe it was on" and it would output "I can't believe it was off" On and off being split word 1 and 2.
Hello again!
I presume you mean to go through the entire string and check each word against the dictionary you have been making, replacing words with the corresponding dictionary if there is one?
If so, you should use the String.Split() method to split the string into an array of strings, each corresponding to one word. Then check these in turn against the dictionary, and build up an output string based on the results of this check - either the original word or the dictionary word if there is one.
-
March 29th, 2012, 08:51 AM
#18
Re: Need Help with Parser C#
After a long morning of trying I decided to go with a Var method of doing it and it works. Thanks for the help though! Trying to figure out how to change the dictionary words in the output box to a different colour, hmmm
-
March 29th, 2012, 10:31 AM
#19
Re: Need Help with Parser C#
Originally Posted by dahrull
After a long morning of trying I decided to go with a Var method of doing it and it works. Thanks for the help though! Trying to figure out how to change the dictionary words in the output box to a different colour, hmmm
The different colour idea sounds nice. Just to get you started, you will need the RichTextBox to do this - a TextBox can only have one colour for all the text.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|