Why not just looking at the help page for System.String?
The trivial way is this:
static string ExtractCompany(string source) {
int bra = source.IndexOf('[');
int ket = source.IndexOf(']');
return source.Substring(bra, ket - bra - 1);
}
More sophisticated way would be using Regular Expression with the pattern "\[.*\]":
using Regex = System.Text.RegularExpressions.Regex;
static string ExtractCompany(string source) {
string pattern = @"\[.*\]";
Regex regex = new Regex(pattern);
var matches = regex.Matches(source);
if (matches.Count < 1) return;
return matches[0].Value.Trim(new char[] { '[', ']' });
}
—SA