我正在C#中工作,并且正在尝试检查字符串中的值{some value}
。最重要的是,我正在寻找字符串是否包含{},介于两者之间。我在想正则表达式,但我真的不知道如何在String.Contains中实现它。我试过创建一个reg-ex实例,并将其传递到Contains中,但这似乎不起作用。请让我知道是否有更简单的方法。
if (uri.Contains("{one word}"))
{
}
return false;
香港专业教育学院尝试过的
public bool SimpleResponseCodeCheck(string callTested, string testName)
{
testParams = SupportingMethodsClass.ReturnXMLData(callTested, testName);
string uri;
string method;
string requestBody;
string expResponseCode;
string actResponseCode;
string statusMessage;
string respBody;
Regex testParameter = new Regex("\\{.+\\}");
testParams.TryGetValue("uri", out uri);
testParams.TryGetValue("method", out method);
testParams.TryGetValue("expResponseCode", out expResponseCode);
testParams.TryGetValue("requestBody", out requestBody);
if (testParameter.IsMatch(uri, 0))
{
}
return false;
}
您正在寻找的Regex.IsMatch()
功能,正是这样做。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句