字符串
str="个/cm<2>";判断是否饮食<和>;
然后替换
if (str.IndexOf('<') > -1 && str.IndexOf('>') > -1)
{
str.Replace("<", "<sup|");
str.Replace(">", "</sup>");
str.Replace("<sup|", "<sup>");
} 我希望:str = "个/cm<sup>2</sup>";
但为何不成功?'<'换成"<"也不行
str="个/cm<2>";判断是否饮食<和>;
然后替换
if (str.IndexOf('<') > -1 && str.IndexOf('>') > -1)
{
str.Replace("<", "<sup|");
str.Replace(">", "</sup>");
str.Replace("<sup|", "<sup>");
} 我希望:str = "个/cm<sup>2</sup>";
但为何不成功?'<'换成"<"也不行
str.Replace(">", "</sup>");
str.Replace("<sup|", "<sup>");改为:str = str.Replace("<", "<sup|");
str = str.Replace(">", "</sup>");
str = str.Replace("<sup|", "<sup>");
Regex reg = new Regex(@"<(.*?)>");
string result =Regex.Replace(str,@"\d+", "sup>$0</sup");
个/cm<sup>2</sup>
str = str.Replace("<", "<sup|");
str = str.Replace(">", "</sup>");
str = str.Replace('|', '>');
Response.Write(Server.HtmlEncode(str) + "<br/>");
Response.Write(str);