Braintree.StringUtil.Underscore C# (CSharp) Method

Underscore() public static method

public static Underscore ( string str ) : string
str string
return string
        public static string Underscore(string str)
        {
            if (str == null)
                return null;

            str = Regex.Replace(str, @"([A-Z]+)([A-Z][a-z])", "$1_$2");
            return Regex.
                Replace(str, @"([a-z])([A-Z])", "$1_$2").
                Replace("-", "_").
                ToLower();
        }
    }

Usage Example

コード例 #1
0
        public virtual List <ValidationError> OnField(string fieldName)
        {
            string key = StringUtil.Underscore(fieldName);

            if (errors.ContainsKey(key))
            {
                return(errors[key]);
            }

            return(null);
        }