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;
}