找到字符串中的所有大写字母单词并使用c#在其周围插入span标记 [英] find all capital letter word in a string and insert span tag around it using c#
本文介绍了找到字符串中的所有大写字母单词并使用c#在其周围插入span标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的字符串。
这是一个非常严格的字符串
我想在它周围添加颜色样式的span标签,如下所示
< span style ='color:Blue;'> THIS< / span>是一个非常< span style ='颜色:蓝色;'> STRANGE< / span> string
我可以通过使用split函数检查isuppercase并插入。
但是有任何reg表达式或任何其他解决方案,以便我可以简单地使用一行代码。如果是这样帮助我。
解决方案
RegEx:(\ b [AZ] + \ b)
替换:< span style ='color:Blue;'>
1< / span>
输入:这是一个非常严格的字符串
输出:< span style ='color:Blue;'> THIS< / span>是一个非常< span style ='颜色:蓝色;'> STRANGE< / span>串
I have a string like this.
"THIS is a very STRANGE string"
I wanted to add span tag with color style around it like below
<span style='color:Blue;'>THIS</span> is a very <span style='color:Blue;'>STRANGE</span> string
i can do this by using split function and check isuppercase and insert.
But is there any reg expression or any other solution so that i can use simply like a one line code. if so help me out.
解决方案
RegEx : "(\b[A-Z]+\b)" Replacement: "<span style='color:Blue;'>
1</span>" Input : "THIS is a very STRANGE string" Output : <span style='color:Blue;'>THIS</span> is a very <span style='color:Blue;'>STRANGE</span> string
这篇关于找到字符串中的所有大写字母单词并使用c#在其周围插入span标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文