C# searching strings
Hi
In C# i am a complete noob and i know very little, How do you search for a particular word in a string in a console application and make that the value of the string.
for example
System.Console.Out.WriteLine("how are you");
string1 = System.Console.In.ReadLine();
//here it would find if the word good is in string1 but they might have //written i am good
//now string1 would be good rather than i am good
{
System.Console.Out.WriteLine("oh you are " + string1);
}
is this possible? and if so how?
In C# i am a complete noob and i know very little, How do you search for a particular word in a string in a console application and make that the value of the string.
for example
System.Console.Out.WriteLine("how are you");
string1 = System.Console.In.ReadLine();
//here it would find if the word good is in string1 but they might have //written i am good
//now string1 would be good rather than i am good
{
System.Console.Out.WriteLine("oh you are " + string1);
}
is this possible? and if so how?
0
Comments
:-)
would that be possible?
string1.ToLower().Contains("i am") and find the index of the m in "i am", add 1, and voila.
I'm not totally familiar with C#, but it would be possible, easily.
/i am([\s\w]*)/
Which should effectively capture any space or word characters proceeding the match of "i am".
Disclaimer: Regex was written on the fly, as a general rule of thumb, you'll never get your Regex right on the first try.