[Solved] Split a string C#


You can use Regex.Matches():

string source = "Mobile: +49 (123) 45678Telephone: +49 (234) 567890Fax: +49 (345) 34234234";

string[] phones = Regex
                 .Matches(source, "[A-Za-z]+: \\+([0-9)( ])+")
                 .Cast<Match>()
                 .Select(i => i.ToString())
                 .ToArray();

OR

You can use IndexOf():

string source = "Mobile: +49 (123) 45678Telephone: +49 (234) 567890Fax: +49 (345) 34234234";

var telephoneIndex = source.IndexOf("Telephone", StringComparison.InvariantCulture);
var faxIndex = source.IndexOf("Fax", StringComparison.InvariantCulture);

string[] phones =
{
    source.Substring(0, telephoneIndex - 1),
    source.Substring(telephoneIndex, faxIndex - 1),
    source.Substring(faxIndex, source.Length - faxIndex)
};

1

solved Split a string C#