CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    Mar 2012
    Posts
    14

    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?

  2. #17
    Join Date
    Jan 2009
    Posts
    596

    Re: Need Help with Parser C#

    Quote Originally Posted by dahrull View Post
    ...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.

  3. #18
    Join Date
    Mar 2012
    Posts
    14

    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

  4. #19
    Join Date
    Jan 2009
    Posts
    596

    Re: Need Help with Parser C#

    Quote Originally Posted by dahrull View Post
    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.

Page 2 of 2 FirstFirst 12

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
  •  





Click Here to Expand Forum to Full Width

Featured