im trying to find a way in c# to replace first occurance of a regular expression in a string.
so if string = " found 1 found 2 found 3"
i want to do something like :
string = replacefirst("found","")
to give results:
string = " 1 found 2 found 3"
thanx
|
Go4Expert Founder
|
![]() |
| 25Jun2007,10:59 | #2 |
|
As far as I can remember there is no direct function and so you need to be splitting it then replacing the string and then concatenate it back to get the complete string.
|
|
Light Poster
|
|
| 25Jun2007,11:40 | #3 |
|
yeah i thought of that option too but the problem seems to be it wont let me split it on such a long combination of characters such as "i_love_c#"
|
|
Go4Expert Founder
|
![]() |
| 25Jun2007,13:42 | #4 |
|
use the substring function to get the part of the string.
|
|
Newbie Member
|
|
| 15Jun2010,10:19 | #5 |
|
this solution might help you
string a = @"abc def ghijklmnopwxyzabcdefghijklmnop"; a = System.Text.RegularExpressions.Regex.Replace(a, "^(a)b(c)", "yogesh"); Response.Write(a.ToString()); |

