-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNumberPadTranslator.cs
More file actions
73 lines (57 loc) · 2.48 KB
/
NumberPadTranslator.cs
File metadata and controls
73 lines (57 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Globalization;
namespace net.iskai.tools.TelephoneNumbers
{
static class NumberPadTranslator
{
#region Static Fields
static readonly Dictionary<string , int> Keys = new Dictionary<string , int>
{
{"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},
{"X", 9},
{"Y", 9},
{"Z", 9}
};
#endregion
public static string Translate( string dialledNumber )
{
var result = string.Empty;
for ( var n = 0 ; n < dialledNumber.Length ; n++ )
{
char c = dialledNumber[ n ];
if ( Char.IsLetter( c ) )
{
var dictKey = dialledNumber[ n ].ToString( CultureInfo.InvariantCulture ).ToUpper( );
if ( Keys.ContainsKey( dictKey ) )
result += Keys[ dictKey ].ToString( CultureInfo.InvariantCulture );
}
else
result += c.ToString( CultureInfo.InvariantCulture );
}
return result;
}
}
}