Determines whether [contains] [the specified target]. - CSharp System

CSharp examples for System:String Contain

Description

Determines whether [contains] [the specified target].

Demo Code

//   The MIT License (MIT)
using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System;//from   w ww.j  a  va2  s .  co  m

public class Main{
        /// <summary>
        /// Determines whether [contains] [the specified target].
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="value">The value.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="culture">The culture.</param>
        /// <returns>
        ///   <c>true</c> if [contains] [the specified target]; otherwise, <c>false</c>.
        /// </returns>
        public static bool Contains(string target, string value, int startIndex, CultureInfo culture = null)
        {
            culture = CultureUtils.GetCurrentCultureIfNull(culture);

            return target != null && value != null && culture.CompareInfo.IndexOf(target, value, startIndex) >= 0;
        }
        /// <summary>
        /// Determines whether [contains] [the specified target].
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="value">The value.</param>
        /// <param name="culture">The culture.</param>
        /// <returns>
        ///   <c>true</c> if [contains] [the specified target]; otherwise, <c>false</c>.
        /// </returns>
        public static bool Contains(string target, string value, CultureInfo culture = null)
        {
            culture = CultureUtils.GetCurrentCultureIfNull(culture);

            return target != null && value != null && culture.CompareInfo.IndexOf(target, value) >= 0;
        }
        /// <summary>
        /// Determines whether [contains] [the specified target].
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="value">The value.</param>
        /// <param name="startIndex">The start index.</param>
        /// <param name="comparisonType">Type of the comparison.</param>
        /// <returns>
        ///   <c>true</c> if [contains] [the specified target]; otherwise, <c>false</c>.
        /// </returns>
        public static bool Contains(string target, string value, int startIndex, StringComparison comparisonType)
        {
            return target != null && value != null && target.IndexOf(value, startIndex, comparisonType) >= 0;
        }
        /// <summary>
        /// Determines whether the [value] [contains] in [the specified target].
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="value">The value.</param>
        /// <param name="comparisonType">Type of the comparison.</param>
        /// <returns>
        ///   <c>true</c> if the [value] [contains] in [the specified target]; otherwise, <c>false</c>.
        /// </returns>
        public static bool Contains(string target, string value, StringComparison comparisonType)
        {
            return target != null && value != null && target.IndexOf(value, comparisonType) >= 0;
        }
}

Related Tutorials