我正在使用 Twitter API 并希望将所有 URL 转换为超链接。
您想到的最有效的方法是什么?
来自
string myString = "This is my tweet check it out http://tinyurl.com/blah";
到
This is my tweet check it out <a href="http://tinyurl.com/blah">http://tinyurl.com/>blah</a>
最佳答案
正则表达式可能是您完成此类任务的 friend :
Regex r = new Regex(@"(https?://[^\s]+)");
myString = r.Replace(myString, "<a href=\"$1\">$1</a>");
匹配 URL 的正则表达式可能需要一些工作。
关于c# - 将 URL 转换为 C# 字符串中的超链接的最简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32637/