Message Boards Message Boards

0
|
4487 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Can we Substitue numbers for letters and back?

Posted 9 years ago
POSTED BY: Paul Cleary
2 Replies

ReplaceAll or /. ?

p = {{1, 3, 9, 8, 5, 4, 2, 7, 6}, {1, 5, 2, 8, 4, 3, 7, 6, 9}, {1, 5, 7, 3, 2, 6, 8, 4, 9}};
txt = {"INTRODUCE", "REDUCTION"};
FromDigits[Characters[txt[[2]]] /. Thread[Characters[txt[[1]]] -> p[[1]]]]
(*864279153*)

Another way is StringReplace but that outputs number as string:

StringReplace["REDUCTION", Thread[Characters[txt[[1]]] -> ToString /@ p[[1]]]]
(*"864279153"*)
POSTED BY: Vitaliy Kaurov
Posted 9 years ago

Excellent, thank you Vitaliy, already amended to account for the list.

POSTED BY: Paul Cleary
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract