【发布时间】:2015-08-01 16:54:42
【问题描述】:
我正在尝试解析字符串的内容以查看字符串是否包含 url,将完整的字符串转换为 html,以使字符串可点击。
我不确定是否有更智能的方法来执行此操作,但我开始尝试使用用于字符串的 Split 方法或 C# 中的 Regex.Split 创建解析器。但我找不到一个好的方法。
(它是一个 ASP.NET MVC 应用程序,所以也许有一些更聪明的方法)
我想前任。转换字符串;
"Customer office is responsible for this. Contact info can be found {link}{www.customerservice.com}{here!}{link} More info can be found {link}{www.customerservice.com/moreinfo}{here!}{link}"
进入
"Customer office is responsible for this. Contact info can be found <a href=www.customerservice.com>here!</a> More info can be found <a href=www.customerservice.com/moreinfo>here!</a>"
即
{link}{url}{text}{link} --> <a href=url>text</a>
谁有好的建议?我还可以更改输入字符串的格式。
【问题讨论】:
-
尝试使用一些模板引擎,这里有几个:stackoverflow.com/a/340243/351383
标签: c# asp.net regex string parsing