Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have two textbox -
Textbox1 and textbox 1

I want to parse text -

double = hello
code=how
enjoy=are
today=you

If I type "double" in textbox1 it will show "hello" in textbox two.

suppose I type texbox1 -
--------------------------
double code enjoy today

in textbox2 will show -
--------------------------
hello how are you
Posted
Updated 3-Sep-15 7:55am
v2
Comments
Maciej Los 24-Aug-15 4:26am    
If user will input any other word, what output you do expect?
doublecode 24-Aug-15 6:48am    
if input got any other word it will be do nothing...just work like regular...

if textbox1 is google textbox2 will be google.
no change...
Thanks7872 24-Aug-15 5:33am    
Why?
doublecode 24-Aug-15 6:47am    
because of my project need this.
Thanks7872 24-Aug-15 6:58am    
There exist no dictionary which says that double means hello. All you can do is check it manually e.g. maintain the collection somewhere.

I'd use a Dictionary<string,> and the word to replace is the key and the word to replace with is the value. Loop through your dictionary and replace each key with each value using RegEx or Replace. You'll have to do something to ensure the case remains the same though, if you google "c# find replace keep case" you'll probably find sample code.
 
Share this answer
 
Comments
doublecode 24-Aug-15 6:44am    
Thanks for your answer. It's helpful .I am googling it now as you said.
 
Share this answer
 
v2
Comments
doublecode 24-Aug-15 6:45am    
thank you so much for reply with example. OK let me try first.
Maybe not the best, but this is how I would do it:

Set up a Dictionary<string,string> for all of your words. The key is "double", the value is "hello" etc.

parse the value of the textbox in it's entirety each time like so:

C#
Dictionary<string,string> cypher = new Dictionary<string,string>
{
  {"double","hello"},
  ///etc
};

string Decode(string code){
    return code
            .split(' ')  //Split the phrase into words
            .Select(c=> 
                cypher.ContainsKey(c)  //Check the work is in the dictionary
                   ?cypher[c]          //Return the decoded word
                   :c);                //return the code word (or whatever)
}



No idea why you want this. There are much better cyphers out there that use full words and even sentences. Granted they are more complex to write codes for, though

Hope that helps ^_^

Andy
 
Share this answer
 
Comments
doublecode 24-Aug-15 6:47am    
Heee..your idea is nice.But it's hard to me. Hee....

Anyway thank you so much for your nice reply with example.
I want to give you one completely different advice though. It looks like you are looking for the easy way of doing something. This is not what decent software engineer do, when it comes to some topic really important for their work. Such people focus on different priorities: learn the subject in depth, to get the best possible competency, to get to the root of things, completely ignoring such factor as the ease of learning. If some way is harder but better, they choose the hard way. More exactly, they make their work easy enough by using their inventiveness and deep understanding of things. If your attitudes are different from that, my advice would be: leave the profession before you got major frustration.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900