Use a regex:
Public Dim regex As Regex = New Regex( "\#\#Date:4\#\#", _
RegexOptions.Multiline _
Or RegexOptions.CultureInvariant _
Or RegexOptions.IgnorePatternWhitespace _
Or RegexOptions.Compiled _
)
Dim result As String = regex.Replace(InputText,DateTime.Now.ToShortDateString())
"when I use Dim result As String = regex.Replace("some texts ##Date:4## some text ##Date:10##", DateTime.Now.ToShortDateString()) the output is 'some texts 12/19/2014 some text 12/19/2014' Note the date are same even if I use different number (4 and 10)"
You still use a Regex, but it needs a small mod to extract the "number" info into a separate group, parse that, and use it for the substitution. Only thing is, because they are different dates, you need a loop or a replace evaluator (which is a lot harder to get your brain round:
Advanced Regex.Replace handling[
^])
The loop version is pretty simple:
Dim input As String = "some texts ##Date:4## some text ##Date:10##"
Dim forwardDate As New Regex("\#\#Date:(?<DaysCount>\d+)\#\#")
Dim output As String = input
Dim now As DateTime = DateTime.Now
For Each m As Match In forwardDate.Matches(input)
Dim days As Integer = Integer.Parse(m.Groups("DaysCount").Value)
output = Regex.Replace(output, m.Value, now.AddDays(days).ToShortDateString())
Next