我有一个字符串:
@reseller-slogan:"/Slogan.png";\r\n@reseller-slogan:"/Slogan.png";\r\n@reseller-slogan:"/Slogan.png";\r\n@reseller-slogan:"/Slogan.png";\r\n
如何匹配并仅返回C#中第一次出现的@reseller-slogan:"/Slogan.png"
?
答案 0 :(得分:0)
如果您想使用RegEx解决任务,可以使用以下任务:
string sourcestring = "your slogan input string";
Regex re = new Regex(@"\@reseller\-slogan:\""\/Slogan\.png\""");
Match m = re.Match(sourcestring);
另一种解决方案可能是使用这样的字符串函数:
string sourcestring = "your slogan input string";
string pattern = "@reseller-slogan:\"/Slogan.png\"";
string patternReplacement = "@reseller-slogan:\"/MyNewSlogan.png\"";
int strIndex = sourcestring.indexOf(pattern);
string resultStr = sourcestring.Remove(strIndex, pattern.Length)
.Insert(strIndex, patternReplacement);