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.

2 Answers 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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Link only answers are not very good - if you could summarize or even give the answer directly, so much better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.