Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Invasion11

macrumors newbie
Original poster
Jul 27, 2011
6
0
Wirelessly posted (Mozilla/5.0 (iPod; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

What I'm wanting is a way a user can enter some text (example, the word "hello") and have those letters of the word be changed into numbers when a button is pressed. (hello, h=10, e=47, l=23, o=9) (final=1047239)and then a way to reverse the process.
 
Wirelessly posted (Mozilla/5.0 (iPod; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

What I'm wanting is a way a user can enter some text (example, the word "hello") and have those letters of the word be changed into numbers when a button is pressed. (hello, h=10, e=47, l=23, o=9) (final=1047239)and then a way to reverse the process.

Have a look at UITextViewDelegate.

p.s. a more descriptive subject might attracted the keener minds.
 
Last edited:
I'd do something like this to convert it from "hello" into "1047239":

Code:
NSArray *alphabet = [[NSArray alloc] initWithObjects:@"h", @"e", @"l", @"o", nil];
NSArray *numbers = [[NSArray alloc] initWithObjects:@"10", @"47", @"23", @"9", nil];

NSString *input = @"hello"; //set to the input from the user
NSString *newString = @"";
for (int i = 0; i < input.length; i++) {
    NSString *letter = [input substringToIndex:i];
    letter = [letter substringFromIndex:letter.length-1];
    int index = [alphabet indexOfObjectIdenticalTo:letter];
    NSString *newValue = [number objectAtIndex:index];
    newString = [NSString stringWithFormat:@"%@%@", newString, newValue];
}
 
I can see the encoding being doable but the decoding seems somewhat problematic. Using the example given (1047239), how would the algorithm know whether each letter comes from one or two digits?
 
Wirelessly posted (Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3)

dejo said:
I can see the encoding being doable but the decoding seems somewhat problematic. Using the example given (1047239), how would the algorithm know whether each letter comes from one or two digits?

I can see it as being problematic, but it might be doable. Maybe start by analyzing each digit. 7, 8, and 9 can only be single digit numbers. 0 has to be the second digit in a 2 digit number. Every number greater than 2 cannot be the first digit in a 2 digit number. Maybe you can "eliminate" enough numbers to make enough of a word to find possible matches in a dictionary and make a guess. :)
 
Oh...

It can't?

A ha! I didn't read the first post closely enough. I had assumed A = 1; B = 2; ... Z= 26.:eek:

How are the numeric values being derived for each letter? Are they arbitrary, or are these well-known codes that I'm ignorant of?

Also, I think I'm gonna need thicker glasses.;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.