I want to find First Word matching from Given Text and replace with another word, using Regex.
Consider following string as an Example Text
Which type is your item? i suppose that the item isn’t a string, if so
you can override ToString() method in
the item class and use the jayant’s
code.
I want to search first “item” word in it and replace that with text “hello”. Remember i just want to replace first “item” word only and not all.
So output of above text would be something like following.
Which type is your hello? i suppose that the item isn’t a string, if so
you can override ToString() method in
the item class and use the jayant’s
code.
I am using C# Programming to do this and I would prefer to use Regex if possible.
Can anyone please help me with this.
You can use the
Regex.Replace()method with the 3rd parameter (maximum replacements):See it on ideone
(Though in this case you don’t really need Regex because you are searching for a constant.)