CSharp examples for System:String Contain
Returns the part of the string before the first occurrence of the given string, or null when the original text does not contain the text to find.
using System;/*from www . j ava 2 s .c om*/ public class Main{ /// <summary> /// Returns the part of the string before the first occurrence of the given string, /// or null when the original text does not contain the text to find. /// </summary> public static string BeforeFirst(this string originalText, string textToFind) { if (String.IsNullOrEmpty(originalText) || !originalText.Contains(textToFind)) { return null; } return originalText.Substring(0, originalText.IndexOf(textToFind, StringComparison.Ordinal)); } }