Hi there I had a look about before posting and couldn’t really figure out how to do this so I was wondering if anyone could help.
Basically, my code just now works like, if I enter a word in the text box and then click a button, it displays the split word from my dictionary in text box 2.
For example, if my dictionary file contains black, white and I enter black into text box 1 and then click a button, white displays in text box 2.
…you get me?
So anyway, I’m trying to get it so if I enter a line of text in text box 1 it’ll copy that line of text into text box 2 and change the word. So
“my chair has a black cushion” would translate to “my chair has a white cushion”
private void btnTrans_Click(object sender, EventArgs e)
{
string outputString = null;
if (d.TryGetValue(inputBx.Text, out outputString))
{
outputBx.Text = inputBx.Text + outputString;
}
else
{
outputBx.Text = "Unknown";
}
}
I’m not sure how i’d go about editing that to fit my needs, so any help?
You will probably want to replace kvp.Key with spaces on left and right to kvp.Value with spaces on left and right, to ensure you don’t replace parts of words, or you can ensure the dictionary’s keys and values are all padded with spaces on left and right.
With dictionary:
{“White”, “Black”}
{“Black”, “White”}
There will be a problem if the sentence contains both white and black.
An alternative would be Jetti’s answer.