我在变量responseString
{
"CreateCustomerResponse": {
"ServiceContextType": {
"Status": {
"Code": "EI7",
"MessageType": "ERROR",
"Message": "Email Oops! Looks like you've already created an account. Please <a href='/account'>click here to sign in.</a>"
}
}
}
}
我想将收到的href
值替换为https://www.myweb.com/signin/
。有可能吗?
string responseString = client.POST(relativeURL, createCustomerRequest, contentType);
responseString = //Replace /account with `https://www.myweb.com/signin/`
答案 0 :(得分:1)
您可以使用String函数replace(),replaceAll()等。 就像这样:
String responseString = client.POST(relativeURL, createCustomerRequest, contentType);
String responseStringReplaced=responseString.replace("/account","https://www.myweb.com/signin/");
答案 1 :(得分:0)
你可以使用这样的正则表达式来实现:
string responseString = client.POST(relativeURL, createCustomerRequest, contentType);
string replace = "https://www.myweb.com/signin/";
string result = Regex.Replace(responseString, @"href='(.*?)'", $"href='{replace}'");
// => ...href='https://www.myweb.com/signin/'>click here to sign in.</a>...