0

I Have some text file. theses texts contain a string like this(a part of text):

<abbr class="word p1"">dd</abbr>
<img src"D:\Images\1.png">
<abbr class="word p1">dd</abbr>
<img src"D:\ticket\t\1.png">

In each text file,(D:\Images\1.png) png name is different but it is always numbers(from 1 to 114)for example(1,2,3,10,...)

I want to replace this text D:\Images\[number].png with a specific text for expample:

string newtext=Replace("D:\Images\[number].png","Something");

How can i do this? thanks.

4

2 回答 2

3

Use a regular expression:

string newtext = Regex.Replace(text, @"(D:\\Images\\)\d+(.png)","$1Something$2");

It will replace the full match, including D:\Images\ and .png, so $1 and $2 puts back what's caught by the parentheses, so that Somthing only replaces the digits.

于 2012-11-26T14:46:35.287 回答
1

Use regular expressions that are represented mostly be the Regex class. See these links:

http://www.codeproject.com/Articles/93804/Using-Regular-Expressions-in-C-NET

http://msdn.microsoft.com/en-us/library/ms228595%28v=vs.80%29.aspx

于 2012-11-26T14:45:12.353 回答