Microsoft.WindowsAzure.Commands.Utilities.CloudService.ServiceSettings.SanitizeStorageAccountName C# (CSharp) Method

SanitizeStorageAccountName() private static method

Sanitize a name for use as a storage account name.
private static SanitizeStorageAccountName ( string name ) : string
name string The potential storage account name.
return string
        private static string SanitizeStorageAccountName(string name)
        {
            // Replace any non-letters or non-digits with their hex equivalent
            StringBuilder builder = new StringBuilder(name.Length);
            foreach (char ch in name)
            {
                if (char.IsLetter(ch) || char.IsDigit(ch))
                {
                    builder.Append(ch);
                }
                else
                {
                    builder.AppendFormat("x{0:X}", (ushort)ch);
                }
            }

            // Trim the sanitized name to at most 24 characters.
            name = builder.ToString(
                0,
                Math.Min(builder.Length, MaximumStorageAccountNameLength));

            if (name.Length < 3)
            {
                name = name.PadRight(3, '0');
            }

            return name;
        }