or, with a regular expression.
using System.Text.RegularExpressions; ... var value = Regex.Match( "super exemple of string key : text I want to keep - end of my string", "key : (.*) - ") .Groups[1].Value;
with an example.
You can decide if it can be brute force.
or
as a proven extension method
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 string source, string left, string right) { return Regex.Match( source, string.Format("{0}(.*){1}", left, right)) .Groups[1].Value; } }
Jodrell Feb 25 '15 at 15:54 2015-02-25 15:54
source share