Question: If I have a string like **MCCORMIC 3H R Final 08-26-2011.dwg** or even **MCCORMIC SMITH 2N L Final 08-26-2011.dwg** and I wanted to capture the **R** in the first string or the **L** in the second string in a variable, what is the best method for doing so? I was thinking about trying the below statement but it does not work.

```
string filename = "MCCORMIC 3H R Final 08-26-2011.dwg"
string WhichArea = "";
int WhichIndex = 0;

WhichIndex = filename.IndexOf("Final");
WhichArea = filename.Substring(WhichIndex - 1,1); //Trying to get the R in front of word Final 

```

Answer: 
Just split by space:

```
var parts = filename.Split(new [] {' '}, 
                            StringSplitOptions.RemoveEmptyEntries);

WhichArea = parts[parts.Length - 3];

```

It looks like the file names have a very specific format, so this will work just fine.

Even with any number of spaces, using `StringSplitOptions.RemoveEmptyEntries` means spaces will not be part of the split result set.

Code updated to deal with both examples - [thanks Nikola](https://stackoverflow.com/questions/12287790/search-string-pattern/12287810#comment16483487_12287810).
I had to do something similar, but with Mirostation drawings instead of Autocad. I used regex in my case. Here's what I did, just in case you feel like making it more complex.

```
string filename = "MCCORMIC 3H R Final 08-26-2011.dwg"; 
string filename2 = "MCCORMIC SMITH 2N L Final 08-26-2011.dwg";

Console.WriteLine(TheMatch(filename));
Console.WriteLine(TheMatch(filename2));

public string TheMatch(string filename) {   
    Regex reg = new Regex(@"[A-Za-z0-9]*\s*([A-Z])\s*Final .*\.dwg");
    Match match = reg.Match(filename);
    if(match.Success) {
        return match.Groups[1].Value;
    }
    return String.Empty;
}

```