Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用周围的||符号转换字符串中的值。例如,||more info||必须更改为<a href="#">more info</a>. 如何在将文本留在中间的同时执行此操作(“更多信息”可以是其他任何内容)?
||
||more info||
<a href="#">more info</a>
这可能是做你想做的最简单的方法:
var pattern = @"\|\|(.+?)\|\|"; var replacement = @"<a href=""#"">$1</a>"; var input = "you can get ||more info|| here"; var result = Regex.Replace(input, pattern, replacement); Console.WriteLine (result);