Get Preceding String - CSharp System

CSharp examples for System:String SubString

Description

Get Preceding String

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  w  w  w.j a  v  a 2 s  .  c  om*/

public class Main{
        public static string GetPrecedingString(this string str, string value)
		{
			var index = str.IndexOf(value);

			if (index < 0)
			{
				return null;
			}
			
			if (index == 0)
			{
				return string.Empty;
			}

			return str.Substring(0, index);
		}
}

Related Tutorials