ASP.NET parse string and replace with usercontrol

Izi

Izi

Soldato
Joined
9 Dec 2007
Posts
2,718
I in my article body content I have files embded as so:

<# FileID='4494' Link='' LinkText='' Resize='185' CssClass='' #>

At run time I need to replace these with the actual file its self (be it a image or link to a file)

How would you go about getting the properties of the string in to a class?
 
if using regex, what expression would you use? Really need to learn more about regex...

so far:string expression = @"\w*(&lt;%)(.)(%&gt)*";
 
Got it working using:

string expression = @"\w*(&lt;%)(.*.)(%&gt)*";

However, would still be interested to know other peoples approach on this?
 
in case anyone needs this in the future this did the trick:

public static string ParseBody(string body)
{
string pattern = @"\[#\s+((FileID=(?<FileID>[\w ]*)|Link=(?<Link>[\w ]*)|LinkText=(?<LinkText>[\w ]*)|Resize=(?<Resize>[\w ]*)|CssClass=(?<CssClass>[\w ]*))\s*)*#\]";

MatchCollection matches = Regex.Matches(body, pattern);


foreach (Match m in matches)
{
EmbedFileHelperClass item = new EmbedFileHelperClass();
item.FileID = Convert.ToInt32(m.Groups["FileID"].Value);
item.Link = m.Groups["Link"].Value;
item.LinkText = m.Groups["LinkText"].Value;
item.Resize = Convert.ToInt32(m.Groups["Resize"].Value);
item.CssClass = m.Groups["CssClass"].Value;

string emdedHtml = processEmbedFile(FileManager.GetFileByID(item.FileID), item);
body = body.Replace(m.Value, emdedHtml);

}

return body;

}
 
Back
Top Bottom