WikiFunctions.Tools.CaseInsensitive C# (CSharp) Method

CaseInsensitive() public static method

Returns a regex case insensitive version of a string for the first letter only e.g. "Category" returns "[Cc]ategory"
public static CaseInsensitive ( string input ) : string
input string
return string
        public static string CaseInsensitive(string input)
        {
            if (!string.IsNullOrEmpty(input) && char.IsLetter(input[0]) &&
                (char.ToUpper(input[0]) != char.ToLower(input[0])))
            {
                input = input.Trim();
                // escaping breaks many places that already escape their data
                return "[" + char.ToUpper(input[0]) + char.ToLower(input[0]) + "]" + input.Remove(0, 1);
            }

            return input;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Generates regexes to match the templates from the template list.
        /// Supports templates with Template: or Msg: at the start
        /// Does not process nested templates
        /// </summary>
        private void RefreshRegexes()
        {
            Regexes.Clear();

            // derive optional template namespace prefixes to allow
            string templ = Variables.NamespacesCaseInsensitive[Namespace.Template];

            if (templ[0] == '(')
            {
                templ = "(?:" + templ.Insert(templ.IndexOf(')'), "|[Mm]sg") + @")?\s*";
            }
            else
            {
                templ = @"(?:" + templ + @"|[Mm]sg:|)\s*";
            }

            foreach (string s in TemplateList)
            {
                if (string.IsNullOrEmpty(s.Trim()))
                {
                    continue;
                }

                Regexes.Add(new Regex(@"\{\{\s*" + templ + Tools.CaseInsensitive(Regex.Escape(s)) + @"\s*(\|[^\}]*|)}}",
                                      RegexOptions.Singleline), @"{{subst:" + s + "$1}}");
            }
        }
All Usage Examples Of WikiFunctions.Tools::CaseInsensitive
Tools