开发者

replace html tag in html editor with specific string

hi anyone knows how to replace a html tag in a string with specific characters: e.g.

string s1 =  "<span style="italic">inluding <span style="bold">ot开发者_开发百科her</span> tags </span>";
string s2 =  "<span style="italic">inluding </span><span style="bold">other tags </span>";

i want to replace "span" with "bold" to "bOpen" and "bClose" and to replace "span" with "italic" to "iOpen" and "iClose" in both c# and javascript. thanks very much.

thanks for the response, i did use regular expression to do that: res = Regex.Replace(res, ".*?", replaceHtmlBold); but it cant match the nested tag and none-nested tag at the same time. could you help please?


JavaScript's String Object has a handy function that lets you replace words that occur within the string. So does C#.


Regular expressions are your friends here. I could give you the exact code for your problem, but then you'll miss the point of learning this technique. Here is an Introduction to Regular Expressions and there is this article "C# Regular Expressions". If you need more, Google is your friend.

Good luck!

PS: I realized now what the real problem is. I think you can get away with lookaround techniques and conditionals. Both are summarized here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜