if I have a UILabel: label1.text (maximum length 6 character) In this example GARAGE is the word in it.
is it possible to have code that would make
label1a: G
label1b: A
label1c: R
label1d: A
label1e: G
label1f: E
I need this so I can compare every character in a word with every character in a other word.
Been struggling with this for a couple of days now :S
edit
I got a random word generator that generates word with a length of 6 like ‘GARAGE’ or ‘SAILOR’ it generates it into a label for this We’ll call the label: ‘randomword.text’
now We got a input label where the character display that we put in with our own made keyboard. this label is ‘input.text’
now we can compare those 2 labels with if (randomword.text == input.text’) { NSLog: @’these words are the same’ };
What I want to do is to seperate every letter in random.text: so have label1 say G, label2 say A, label3 say R, label4 say A, label5 say G, label6 say E.
If I separate my input.text in the same way like I did above with random.text I got another 6 UILabel for example have this one separated in label7,8,9,10,11,12. Now I can compare label 1 to label 7, label 2 to 8. etc That way I can see if Letters are on the place they should be even if the entire word do not equal each other.
Still confused by all that stuff about labels. I don’t think your question has anything to do with labels, but with comparing strings or parts of them. So if you wan’t to check if to strings are equal use
[aString isEqualToString:anotherString];(not ==).If you want to extract a letter from a string use
[aString characterAtIndex:i];or[aString substringWithRange:NSMakeRange(i, i+1)].If you want to check if a letter is on a certain position (say i) in a string use:
or
If you want to get ‘what’s shown on a
UILabel‘ asNSStringuseaLabel.text.Hope that helps.