예제 #1
0
    public static string SplitCamelCase(this string input)
    {
        if (input == null)
        {
            return(null);
        }
        if (string.IsNullOrWhiteSpace(input))
        {
            return("");
        }

        var separated = input;

        separated = SplitCamelCaseRegex.Replace(separated, @" $1").Trim();

        //Set ALL CAPS words
        if (_SplitCamelCase_AllCapsWords.Any())
        {
            foreach (var word in _SplitCamelCase_AllCapsWords)
            {
                separated = SplitCamelCase_AllCapsWords_Regexes[word].Replace(separated, word.ToUpper());
            }
        }

        //Capitalize first letter
        var firstChar = separated.First(); //NullOrWhiteSpace handled earlier

        if (char.IsLower(firstChar))
        {
            separated = char.ToUpper(firstChar) + separated.Substring(1);
        }

        return(separated);
    }
예제 #2
0
        /// <summary>
        /// Turn CamelCaseText into Camel case text.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <remarks>Use AppSettings["SplitCamelCase_AllCapsWords"] to specify a comma-delimited list of words that should be ALL CAPS after split</remarks>
        /// <example>
        /// wordWordIDWord1WordWORDWord32Word2
        /// Word Word ID Word 1 Word WORD Word 32 Word 2
        ///
        /// wordWordIDWord1WordWORDWord32WordID2ID
        /// Word Word ID Word 1 Word WORD Word 32 Word ID 2 ID
        ///
        /// WordWordIDWord1WordWORDWord32Word2Aa
        /// Word Word ID Word 1 Word WORD Word 32 Word 2 Aa
        ///
        /// wordWordIDWord1WordWORDWord32Word2A
        /// Word Word ID Word 1 Word WORD Word 32 Word 2 A
        /// </example>
        public static string SplitCamelCase(this string input)
        {
            if (input == null)
            {
                return(null);
            }
            if (string.IsNullOrWhiteSpace(input))
            {
                return("");
            }

            var separated = input;

            separated = SplitCamelCaseRegex.Replace(separated, @" $1").Trim();


            return(separated);
        }