private string AccessToSQL(string accessString)
{
accessString = Regex.Replace(accessString, "dbo_", String.Empty);
accessString = Regex.Replace(accessString, "\"", "'");
accessString = Regex.Replace(accessString, "%START%", startDate);
accessString = Regex.Replace(accessString, "%STOP%", endDate);
string midToSubs = Regex.Match(accessString, @"mid\(.+?\)", RegexOptions.IgnoreCase).Value;
string fieldName = Regex.Replace(Regex.Match(midToSubs, @"\[.+?\]").Value, @"\[|\]", String.Empty);
string toSubString = "SUBSTRING(" + fieldName + ", 2, LEN(" + fieldName + "))";
accessString = Regex.Replace(accessString, @"mid\(.+?\)", toSubString, RegexOptions.IgnoreCase);
return accessString;
}
必须Regex.Replace如何缩短?
答案 0 :(得分:0)
您可以通过一次替换将MID
转换为SUBSTRING
:
accessString = Regex.Replace(accessString,
@"mid\(.*?\[(.+?)\].*?\)",
"SUBSTRING($1, 2, LEN($1))",
RegexOptions.IgnoreCase);