2009-09-22 5 views
-1
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; 
} 

devez doit Regex.Replace comment raccourcir?Comment compresser cette fonction à court de Regex?

Répondre

0

Vous pouvez convertir MID-SUBSTRING avec un seul remplacement:

accessString = Regex.Replace(accessString, 
          @"mid\(.*?\[(.+?)\].*?\)", 
          "SUBSTRING($1, 2, LEN($1))", 
          RegexOptions.IgnoreCase); 
Questions connexes