using System;
using System.Text .RegularExpressions ;
public class Test
{
public static void Main( )
{
var value =
"super exemple of string key : text I want to keep - end of my string"
.Between (
"key : " ,
" - " ) ;
Console.WriteLine ( value) ;
}
}
public static class Ext
{
static string Between( this System.String source, string left, string right)
{
return Regex.Match (
source,
string.Format ( "{0}(.*){1}" , left, right) )
.Groups [ 1 ] .Value ;
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJdmFyIHZhbHVlID0KCQkJCSJzdXBlciBleGVtcGxlIG9mIHN0cmluZyBrZXkgOiB0ZXh0IEkgd2FudCB0byBrZWVwIC0gZW5kIG9mIG15IHN0cmluZyIKCQkJCQkuQmV0d2VlbigKCQkJCSAgICAgICAgImtleSA6ICIsCgkJCQkgICAgICAgICIgLSAiKTsKCQkJCgkJQ29uc29sZS5Xcml0ZUxpbmUodmFsdWUpOwoJfQp9CgpwdWJsaWMgc3RhdGljIGNsYXNzIEV4dAp7CglzdGF0aWMgc3RyaW5nIEJldHdlZW4odGhpcyBTeXN0ZW0uU3RyaW5nIHNvdXJjZSwgc3RyaW5nIGxlZnQsIHN0cmluZyByaWdodCkKCXsKCQlyZXR1cm4gUmVnZXguTWF0Y2goCgkJCQlzb3VyY2UsCgkJCQlzdHJpbmcuRm9ybWF0KCJ7MH0oLiopezF9IiwgbGVmdCwgcmlnaHQpKQoJCQkuR3JvdXBzWzFdLlZhbHVlOwoJfQp9
compilation info
prog.cs(10,7): error CS1061: Type `string' does not contain a definition for `Between' and no extension method `Between' of type `string' could be found. Are you missing an assembly reference?
/usr/lib/mono/4.5/mscorlib.dll (Location of the symbol related to previous error)
Compilation failed: 1 error(s), 0 warnings
stdout