A
Andy Hoe
Hello, I'm new to C# and I am having a small problem. All I want to do is
take a sentence from the user then replace certain words with other ones.
So I started off with this:
string myString = Console.ReadLine();
string editString;
editString = myString.Replace("is", "isn't");
Console.WriteLine(editString);
Which if I entered "This is a test" I got back "Thisn't isn't a test"
I got round this by looking for the word to replace by putting spaces round
the string:
string myString = Console.ReadLine();
string editString;
editString = myString.Replace(" is ", " isn't ");
Console.WriteLine(editString);
Which was fine for this example, but what if there is punctuation involved?
what if I wanted to convert "This is." it wouldn't pick it up because of the
full stop. Would it be best to do it a different way by stripping all the
punctuation out somehow? but then how would you put it back in? is there a
simple way of doing this?
Thanks for any help,
Andy
take a sentence from the user then replace certain words with other ones.
So I started off with this:
string myString = Console.ReadLine();
string editString;
editString = myString.Replace("is", "isn't");
Console.WriteLine(editString);
Which if I entered "This is a test" I got back "Thisn't isn't a test"
I got round this by looking for the word to replace by putting spaces round
the string:
string myString = Console.ReadLine();
string editString;
editString = myString.Replace(" is ", " isn't ");
Console.WriteLine(editString);
Which was fine for this example, but what if there is punctuation involved?
what if I wanted to convert "This is." it wouldn't pick it up because of the
full stop. Would it be best to do it a different way by stripping all the
punctuation out somehow? but then how would you put it back in? is there a
simple way of doing this?
Thanks for any help,
Andy