Do you have a beginning of an algorithm? How does T9 work? An example of text and the corresponding numbers for the transformation of the text?
There is still a minimum of research and explanations to provide before anyone helps you!
paul0007
Posted messages5StatusMembre1
Hello, I have defined the different possible combinations
a = 2 b = 22 c = 222 d = 3 e = 33 f = 333 g = 4 h = 44 i = 444 j = 5 k = 55 l = 555 m = 6 n = 66 o = 666 p = 7 q = 77 r = 777 s = 7777 t = 8 u = 88 v = 888 w = 9 x = 99 y = 999 z =9999
However, I have no idea for the code (I just started with bash..), I was thinking of using tr. Can you help me?
paul0007
Posted messages5StatusMembre1
but with tr it's one letter by one letter so I don't see how to transform the b into 22
paul0007
Posted messages5StatusMembre1
ah .. or we can shorten it by saying that: 2 = a, b, c 3 = c, d, e 4 = f, h, i 5 = j, k, l 6 = m, n, o 7 = p, q, r, s 8 = t, u, v 9 = w, x, y, z
I haven't thought too much about an algorithm yet, because you haven't provided the context of the input (how the letters are transmitted), and how far you want to simulate "intuitive typing" .
So, initially, I would lean towards an array, because a variable cannot start with a digit.
ar[2]=a ar[22]=b ...
paul0007
Posted messages5StatusMembre1
What bothers me is the structure of the bash... I’ll give you my algorithm in natural language so you can understand my reasoning.
Start algo
We ask the user to choose between converting number to letter or letter to number
case 1: number to letter
We ask the user to enter their sequence of numbers then for each number we associate the group of letters (2 = (a/b/c); 3 = (d/e/f)...) which we display on the screen, then we look for an existing word in the file dico.txt with that combination
case 2: letter to number
We ask the user to enter their string of characters then for each letter we associate the corresponding number (a = 2; b = 2, c = 2, d = 3...) which we display on the screen
end algo
Anonymous user
So, for case 1, I stick to the table, which, however, will contain as many expressions in brackets (cf. man 7 regex) as there are digits available on the keyboard:
exprCroc=( [2]='[abc]' [3]='[def]' ...)
the search in dico.txt will simply be done with a
grep
using the regex pattern concatenated from the data provided by the user and retrieved from the table. if the user provides:
23
, then the constructed regex will be
"^[abc][def]$"
.
in both cases, the provided data must be read one character at a time.
while read -n1 l; do test -n "$l" && regex+="$l"; done <<<"mon_mot"
for case 1, we will look for the corresponding value in the table. for case 2, we will use an indirection (cf. man bash).
I have defined the different possible combinations
a = 2
b = 22
c = 222
d = 3
e = 33
f = 333
g = 4
h = 44
i = 444
j = 5
k = 55
l = 555
m = 6
n = 66
o = 666
p = 7
q = 77
r = 777
s = 7777
t = 8
u = 88
v = 888
w = 9
x = 99
y = 999
z =9999
However, I have no idea for the code (I just started with bash..), I was thinking of using tr.
Can you help me?
2 = a, b, c
3 = c, d, e
4 = f, h, i
5 = j, k, l
6 = m, n, o
7 = p, q, r, s
8 = t, u, v
9 = w, x, y, z
?