如果有一个电话号码输入,例如" 555-GET-FOOD",我试图用相应的号码替换字母(即A,B和C = 1)。到目前为止,我有这个:
public enum LetterNumber
{
A = 2, B = 2, C = 2, D = 3, E = 3, F = 3, G = 4, H = 4, I = 4,
J = 5, K = 5, L = 5, M = 6, N = 6, O = 6, P = 7, Q = 7, R = 7,
S = 7, T = 8, U = 8, V = 8, W = 9, Y = 9, Z = 9
}
private bool IsValidNumber(string str)
{
const int VALID_LENGTH = 10;
bool valid = true;
if (str.Length == VALID_LENGTH)
{
foreach (char ch in str)
{
if (char.IsLower(ch))
{
valid = false;
}
}
}
else
{
valid = false;
}
return valid;
}
不幸的是,我不知道使用什么命令将数字替换给定位置的每个字符,或者如何使用该命令。任何帮助将不胜感激!