nsstring

Count string value?

Hey, Im a newbie in cocoa and I have a string and I am trying to count how long it is. I have been searching through Apples docs but I can't find anything. NSString *word = @"word"; How would I figure out how many characters is in a string? Thanks ...

Ordering a list of NSStrings in NSMutableArray?

Is it possible to order an NSMutableArray where it's values are NSStrings? I'm looking to order alphabetically. Thanks ...

How to copy a wchar_t into an NSString?

I'm using stringWithFormat @"%ls" to do it and I only see the first character copied, which makes me think it's still assuming it's a single byte char. Any ideas? ...

How can I put an image inline with an NSString on the iPhone?

I know you can do it on Mac OS X with NSAttributedString but I haven't had much luck with that on the iPhone. I'm trying to basically do a string like "$200" except the dollar sign is replaced by a custom symbol. ...

iPhone SDK NSString To NSDate

I got a string from parsing a XML file which looks like this: Fri, 09 Apr 2010 00:00:45 +0200 and the corresponding pattern should be this "EEE, dd MMM yyyy HH:mm:ss ZZ", but I get (null). This is my code: NSString *dateString = @"Fri, 09 Apr 2010 00:00:45 +0200"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateF...

Placement/Positioning/Alignment of UIScrollView w.r.t. length of Title NSString

I have a scenario where i show stuff like: ----------------------------------- titleview (UITextView) ______________ tArea (UIScrollView) ttextview (UITextView) ----------------------------------- Now here is the condition: Length of titleview's text is dynamic, varies based on ...

-sizeWithFont Functions Differently on Device

So I am seemingly encountering some strange behavior when using NSString's -sizeWithFont family of method calls depending on whether or not I'm invoking it on the iPhone Simulator or an actual device. Simply enough, when the receiver of the -sizeWithFont:constrainedToSize:lineBreakMode: method call is nil, the resulting CGSize passed ba...

iphone read txt file from UIWebView

I can read the data in file.txt file located in local disk. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"txt"]; NSString* Data = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error ]; now, I upload the file.txt file into a website. how can i read the data from the txt ...

SOAP app variables - NSNumber or NSString for integer?

In a SOAP app, all communication with the server is as text, when the server needs an integer it is the text value that gets sent and returned integers are sent back as text. To have the app working with integers one has to convert the returned strings into numbers e.g. NSInteger but then to, for example, save them to an array they must...

NSData to display as a string

Hello all, this is my first post. I am building an iPhone app and stuck with the following: unsigned char hashedChars[32]; CC_SHA256([inputString UTF8String], [inputString lengthOfBytesUsingEncoding:NSASCIIStringEncoding], hashedChars); NSData *hashedData = [NSData dataWithBytes:hashedChars length:32]; NSLog(@"hashedData = %@", hashedDa...

Sending array through email on iphone

Hey guys I need to send the content of an NSMutableArray through email. I have a mailing function but I'm not sure on how to place the content of the array into a NSString to be displayed on the email under each other. Is there a way to place all the content of the array into the string with maybe HTML nextline command between each array...

I get an "EXC_BAD_ACCESS" when I try to read a NSString...

Hello ! This is a (very) simplified version of my iPhone code : @interface x { NSString * name1; NSString * name2; } -init { name1 = @""; name2 = @""; } -(void) a { Foo * foo = [Foo alloc]; name1 = @"uhuh"; name2 = [foo bar]; // return a (NSString *) [foo release]; ...

What would cause objectForKey: to return null with a valid string in place?

I am having an issue with NSDictionary returning null for an NSString even though the string is in the dictionary. Here is the code: - (void)sourceDidChange:(NSNotification *)aNote { NSDictionary *aDict = [aNote userInfo]; DLog(@"%@", aDict); NSString *newSourceString = [aDict objectForKey:@"newSource"]; DLog(@"%@", newS...

What is the difference among NSString alloc:initWithCString versus stringWithUTF8String?

I thought these two methods were (memory allocation-wise) equivalent, however, I was seeing "out of scope" and "NSCFString" in the debugger if I used what I thought was the convenient method (commented out below) and when I switched to the more explicit method my code stopped crashing! Notice that I am getting the string that is being s...

How to get the size of a NSString

Hi. A "quicky": how can I get the size (width) of a NSString? I'm trying to see if the string width of a string to see if it is bigger than a given width of screen, case in which I have to "crop" it and append it with "...", getting the usual behavior of a UILabel. string.length won't do the trick since AAAAAAAA and iiiiii have the sam...

iPhone - database reading method and memory leaks

Hi, in my application, a RSS reader, I get memory leaks that I can't fix because I can't understand from where they come from. Here is the code pointed out by Instruments. -(void) readArticlesFromDatabase { [self setDatabaseInfo]; sqlite3 *database; articles = [[NSMutableArray alloc] init]; if(sqlite3_open([databasePath UTF8String]...

Converting long value to unichar* in objective-c

I'm storing large unicode characters (0x10000+) as long types which eventually need to be converted to NSStrings. Smaller unicode characters can be created as a unichar, and an NSString can be created using [NSString stringWithCharacters:(const unichar *)characters length:(NSUInteger)length] So, I imagine the best way to get an NSStri...

Iphone Leaks NSString

Hi, I have leaks in the following code : NSString * string; - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)str{ string = [NSString stringWithFormat:@"%@", str]; } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { ...

How can I detect if a string contains punctuation marks at the end?

Lets assume I have the string: "Hello I like your shoes #today...!" I am tokenizing the string by spaces: return [string componentsSeparatedByString:@" "]; So my array contains: Hello I like your shoes #today...! I want to focus on "#today...!" any word that has a # in the prefix I am changing the font color. How can I make sur...

How to calculate the height of the text rectangle from an NSString?

I know there is this one: sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: But since the CGSize always has the same height and doesn't adjust to any shrinked text or whatsoever, the CGSize is not telling how heigh the text is. Example: Make a UILabel with 320 x 55 points and put a loooooooooooooong text in there. Let t...