vexe / VFW

MIT License
492 stars 67 forks source link

StringExtensions.ToTitleCase #37

Closed ajboni closed 9 years ago

ajboni commented 9 years ago

Hello! It seems this method is conflicting with $nicename.

     public static string ToTitleCase(this string input)
        {
            input = input.ToLower().Replace("_", " ");
            TextInfo info = CultureInfo.CurrentCulture.TextInfo;
            input = info.ToTitleCase(input).Replace(" ", string.Empty);
            return input;
        }

2015-07-01 23_48_57-unity personal 64bit - vicraider unity - uae - web player_ _dx11_

commenting those three lines, fixes the problem. Its related to regional settings in any way? (latin american system)

2015-07-01 23_52_19-unity personal 64bit - vicraider unity - uae - web player_ _dx11_

vexe commented 9 years ago

What is the actual name of the field? "notificationTime"? or?

ajboni commented 9 years ago

yup, notificationTime, just tested, and the same output as picture 1 (Notificationtime) with these four:

        public float notificationTime;
        public float NotificationTime;
        public float _Notificationtime;
        public float notificationtime;
vexe commented 9 years ago

Insert this:

                if (name.IsPrefix("m_"))
                    result = name.Remove(0, 1);
                else result = name;

                var builder = new StringBuilder();
                for(int i = 0; i < result.Length; i++)
                {
                    var current = result[i];
                    if (current == '_' && i + 1 < result.Length)
                    {
                        var next = result[i + 1];
                        if (char.IsLower(next))
                            next = char.ToUpper(next);
                        builder.Append(next);
                        i++;
                    }
                    else
                        builder.Append(current);
                }

                result = builder.ToString();

Code should look like this http://i.imgur.com/QALrLFK.png

This should fix it. I'll push to master in a bit.

ajboni commented 9 years ago

Perfect! That fixed ! Thanks!