I want to get the word following the "FROM " part in a DB query. With the following code sometimes it works, sometimes it doesn't. It seems to depend on the table name length.

```
Private Function GetTableName(Q As String) As String
    'SELECT * FROM _table WHERE column LIKE '%test%'  

    Dim FROMPos As Integer = Q.ToLower.IndexOf("FROM".ToLower)

    If FROMPos > -1 Then
        Dim FirstSpacePos As Integer = Q.ToLower.IndexOf(Chr(32), FROMPos)

        If FirstSpacePos > -1 Then
            Dim EndSpacePos As Integer = Q.ToLower.IndexOf(Chr(32), FirstSpacePos + 1)

            If EndSpacePos > -1 Then
                'MsgBox(Q.Substring(FirstSpacePos + 1, EndSpacePos - FirstSpacePos))
                Return Q.Substring(FirstSpacePos + 1, EndSpacePos - FirstSpacePos)
            Else
                Return ""
            End If
        Else
            Return ""
        End If
    Else
        Return ""
    End If
End Function

```