Escapes the jquery selector. - CSharp System

CSharp examples for System:String Escape

Description

Escapes the jquery selector.

Demo Code


using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Text;
using System.Linq;
using System.Globalization;
using System.ComponentModel;
using System.Collections.Generic;
using System;/*from   w ww. j a  v  a  2  s . c  o  m*/

public class Main{
        /// <summary>
		/// Escapes the selector. Query requires special characters to be escaped in query
		/// http://api.jquery.com/category/selectors/
		/// </summary>
		/// <param name="attribute">The attribute.</param>
		/// <returns></returns>
		public static string EscapeSelector(this string attribute)
		{
			return Regex.Replace(attribute, string.Format("([{0}])", "/[!\"#$%&'()*+,./:;<=>?@^`{|}~\\]"), @"\\$1");
		}
}

Related Tutorials