|
-
May 18th, 2011, 04:47 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] RegEx.Replace problem.
I have a string which holds html, all the image tags have their src set as a value, I have half set up a function to get the value and look up in the database what the actual url should be.
I now need to replace the various values in the string, how do I pass the function the value that the regex replace is currently evaluating?
Code:
public String replaceID_withImagesrcs(IRepository<Corp.Web.Model.Image> objImages, String Text)
{
String parsedtext;
parsedtext = Text.Replace("complete=\"complete\"", "");
String t18 = @parsedtext;
Corp.Web.Model.Image objImage;
String p18 = @"(?<=img\s+src\=[\x27\x22])(?<Url>[^\x27\x22]*)(?=[\x27\x22])";
Regex.Replace(t18, p18, (objImage = objImages.FindById(Convert.ToInt64(?????????))).URLRefRegexOptions.Singleline);
return t18;
}
Will this even be possible or do I need to look at somehow going through the string and replacing each match individually?
Code:
foreach (Match match in Regex.Matches(t18, p18))
{
Corp.Web.GSP.Model.Image objImage;
objImage = objImages.FindById(Convert.ToInt64(match.Value));
String.Replace(match.Value, objImage.URLRef.ToString());
}
Last edited by FishGuy; May 18th, 2011 at 05:05 AM.
-
May 18th, 2011, 08:01 AM
#2
Thread Starter
Frenzied Member
Re: RegEx.Replace problem.
public String replaceID_withImagesrcs(String OutlineText, IRepository<Corp.Web.Model.Image> objImages)
{
String parsedtext;
parsedtext = OutlineText.Replace("complete=\"complete\"", "");
String t18 = @parsedtext;
String p18 = @"(?<=img\s+src\=[\x27\x22])(?<Url>[^\x27\x22]*)(?=[\x27\x22])";
t18 = Regex.Replace(t18, p18, new MatchEvaluator(delegate(Match match) { return MyMethod(match, objImages); }));
return t18;
}
private static String MyMethod(Match m, IRepository<Corp.Web.Model.Image> objImages)
{
Corp.Web.Model.Image objImage;
objImage = objImages.FindById(Convert.ToInt64(m.Value));
return objImage.URLRef;
//
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|