PDA

View Full Version : get value of NSString as an array?




begdev
Aug 15, 2009, 11:48 PM
I'm learning C again, so that I really understand everything.
My objective is to get the value of a uitextfield input, which I know how to... and then based on each letter in order do something different.
So like if string[1] == a { NSLog(@"its a")}, if string[1] == b { NSLog(@"its a b")} and so on...

Now I know that strings are basically arrays. So if I'm correct, this should be possible, i just get the length of it, then do it for each one.. I'm just having trouble putting this into ObjC code. thanks.



drivefast
Aug 16, 2009, 11:33 AM
use a characterAtIndex: message for your string. (really, if you would just have taken a look the NSString documentation, this should have jumped right at you...)

PhoneyDeveloper
Aug 16, 2009, 12:49 PM
Don't use characterAtIndex.

NSStrings are not just a kind of array.

Read the String Programming Guide.

begdev
Aug 16, 2009, 01:28 PM
use a characterAtIndex: message for your string. (really, if you would just have taken a look the NSString documentation, this should have jumped right at you...)

yeah i just found that heh...
but thanks anyway, documentation isn't really handy for learning the basics and stuff, so i kinda filed it in my head as, "not helpful" but, i guess it is after all.

dejo
Aug 16, 2009, 08:13 PM
documentation isn't really handy for learning the basics and stuff
So what are you using instead?

begdev
Aug 17, 2009, 06:09 PM
So what are you using instead?

books. i just find that when you're learning in the beginning, the documentation isn't very useful for teaching you how to do things.

dejo
Aug 17, 2009, 07:49 PM
books. i just find that when you're learning in the beginning, the documentation isn't very useful for teaching you how to do things.
Good. At least you're using something.