我有很长的字符串,我需要提取在 c 中以 # 开头和结尾的 subsrting
例如:
#insidehash#
子字符串将为:insidehash
我正在寻找上述问题的解决方案
我有很长的字符串,我需要提取在 c 中以 # 开头和结尾的 subsrting
例如:#insidehash# 子字符串将是: insidehash
你可以尝试用正则表达式进行匹配,即
using System.Linq;
using System.Text.RegularExpressions;
...
string text = "123#fragment 1#bla-bla-bla#next#tail"
string[] fragments = Regex
.Matches(text, "(?<=#)[^#]*(?=#)")
.Cast<Match>()
.Select(match => match.Value)
.ToArray();