I created a method and would like to know how to use string interpolation with string.replace inside my method.
I looked through several how to's on Stack Overflow on its use but not with replace. I would like some guidance on how to accomplish this.
private string CheckForEscapeStringInQuotesAndTrim(string csvDataValue)
{
if (Regex.IsMatch(csvDataValue, "[,\"\\r\\n]"))
{
return "\"" + csvDataValue.Replace("\"", "\"\"") + "\"";
}
//trim any unnecessary whitespace
return csvDataValue.Trim();
}
You could simply use csvDataValue.Replace("\\"", "\\"\\"")
as an interpolated expression it will be resolved.
private string CheckForEscapeStringInQuotesAndTrim(string csvDataValue)
{
if (Regex.IsMatch(csvDataValue, "[,\"\\r\\n]"))
{
return $"\"{csvDataValue.Replace("\"", "\"\"")}\"";
}
//trim any unnecessary whitespace
return csvDataValue.Trim();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.