### 在以下字符串中获取表名的最有效方法

SELECT [t0]。[Id]，[t0]。[CODE] AS [arg0]，[t0]。[DESC] AS [arg1] FROM [SchemaName]。[TableName] AS [t0] WHERE（[t0]。[Id]＆lt;＆gt; @ p0）

#### 2 个答案:

`````` string q = @"SELECT [t0].[Id], [t0].[CODE] AS [arg0], [t0].[DESC] AS [arg1] FROM [SchemaName].[TableName] AS [t0] WHERE ([t0].[Id] <> @p0)";
int fromIndex = q.IndexOf("FROM")+5;
int asIndex = q.IndexOf("AS",fromIndex);
q = q.Substring(fromIndex, asIndex - fromIndex);
``````

``````string data = "SELECT [t0].[Id], [t0].[CODE] AS [arg0], [t0].[DESC] AS [arg1] FROM [SchemaName].[TableName] AS [t0] WHERE ([t0].[Id] <> @p0)";
Regex re = new Regex(@"FROM ((\[\w+\]\.?){2}) AS");
Match m = re.Match(data);
if (m.Success){ Console.WriteLine(m.Groups[1]); }
``````

``````string data = "SELECT [t0].[Id], [t0].[CODE] AS [arg0], [t0].[DESC] AS [arg1] FROM [SchemaName].[TableName] AS [t0] WHERE ([t0].[Id] <> @p0)";
Regex re = new Regex(@"FROM \[(\w+)\]\.\[(\w+)\]\ AS");
Match m = re.Match(data);
if (m.Success){ Console.WriteLine("{0}.{1}", m.Groups[1], m.Groups[2]); }
``````