nsstring

stringWithFormat vs. initWithFormat on NSString.

I am wondering what differences such as disadvantages and/or advantages there are to declaring an NSString this way: NSString *noInit = [NSString stringWithFormat:@"lolcatz %d", i]; as opposed to: NSString *withInit = [[NSString alloc] initWithFormat:@"Hai %d", i]; What was the motivation of putting stringWithFormat instead of just...

NSString does not have to be released in cellForRowAtIndexPath: method?

In order to set cell.textLabel.text in the cellForRowAtIndexPath method I alloc and init a string. If I release this string after setting cell.textLabel.text, then the program will crash after doing this several times. Why doesn't it crash the first time? Since the string was alloced and inited, doesn't it have to be released? Here's t...

How to test 2 NSString to see if they're the same?

So I want to test 2 NSString to see if they're the same while I'm typing so like: NSString *theOriginalString = [NSString stringWithFormat:@"Superman"]; NSString *theTypedString = [textView string]; I want to see if theTypedString is wrong while I type it out so a warning pops out if someone typed the wrong answer. Thank you in adv...

% sign in string objective c

i am wondering how i do a % sign within a NSString, i have tried \% and \\% ...

How to use NSLineSeparatorCharacter and NSParagraphSeparatorCharacter?

I wonder how I can use the constants NSLineSeparatorCharacter and NSParagraphSeparatorCharacter as a parameter to a function instead of hard coding \n. - (id)initWithSeparator:(id)separator { m_separator = separator; } What would be the correct parameter type and what conversion needs to be done? Depending on the file contents I wish...

stringWithContentOfURL return an empty string

Hi, i have a problem with the method "[NSStrng stringWithContentOfURL:url]"; all things worked so fine until i change my url from a web address to an ip address with which i got an empty string. Did you have a solution or an idea? Thks ...

extract specific string in NSString

hi, i think it is a simple question but i dont know how to solve it. i have a NSString that containes html content. i want to extract some tags. NSString *string=@"test some text <img src='http://www.xyz.com/a.jpg' > blah blah <a href='asdfg'>aaaa</a> bbbb cccc"; i want to take img & "a" tag into new string. then i will display it i...

iPad/iPhone - NSString drawInRect not word wrapping

I'm using the following to render some text in a UIView. - (void) drawRect:(CGRect)rect { NSString* text = @"asdf asdf asdf asdf asdf asdf asdf"; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]); CGContextFillRect(context, rect); CGCon...

Converting NSString to NSDate (and back again)

How would I convert an NSString like "01/02/10" (meaning 1st February 2010) into an NSDate? And how could I turn the NSDate back into a string? ...

Force update of NSTextField

Hello, I have a NSTextField that gets updated when my app searches through an array: for (NSString *file in fileinDir) { processedFiles = processedFiles + 1; NSArray*filesinDevice = [fm contentsOfDirectoryAtPath:[[dict objectForKey:NSWorkspaceVolumeURLKey] path] error:nil]; [progressLabel setStringValue:[NSStr...

Using xcode, how do you split NSString into component parts

Hi! In XCode, if I have an NSString containing a number, ie @"12345", how do I split it into an array representing component parts, ie "1", "2", "3", "4", "5"... There is a componentsSeparatedByString on the NSString object, but in this case there is no delimiter... Any help is much appreciated! Graham ...

[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,0)];

i m using sqlite i am geting a return value frmo DB in this manner "returnCount = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,0)];" but the returend value is an integer value. how can i get a int value instead of paasing it in string...like this thing here "[NSString stringWithUTF8String:(char *)sqlite3_col...

Convert NSData to NSString and ignore null bytes?

I need to convert a NSData object to an NSString. It is meant to be gibberish but I need it for debbuging. When I use NSString's initWithData, it breaks as the data has NULL bytes. How can I make it ignore the null bytes and get a proper string? ...

Add suffix to file name before extension

What's the simplest way to add a suffix to a file name before the extension in Objective-C? Example Original name: image.png Suffix: ~ipad Result: image~ipad.png ...

NSString comparison question

I am trying to test to see if an NSString has the letters "PDF" as the first 3 letters: if ([[[profiles stringForKey:@"response"] characterAtIndex:0] isEqualToString:@"P"]) { //TODO } I started with this approach to see if I could at least narrow it down to those strings that start with "P" but I am getting an erro...

Best way to display barcodes from NSString

Hi All, Just wondering what is the best way to display a barcode given a string on the iPhone. I have looked over stackoverflow and google and a few people have different ways each requiring a decent amount of work (I think) and also slightly old so I wanted to get it right first time. One way I've read is using a custom font that you ...

What is the most efficient way to count number of word in NSString without using regex?

I am a bit new to Objective C and was wondering if there is a better way to count words in a string. ie: NSString *str = @"this is a string"; // return should be 4 words .. The way I now how to do it is by breaking the string into an array of words space (' ') character and count the array. Any advise will be appreciated! Thanks!!...

NSString is not appearing properly

I have the following NSString: NSString* searchURL = [NSString stringWithFormat:@"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22%@%22)%0A%09%09&amp;format=json&amp;env=http%3A%2F%2Fdatatables.org%2Falltables.env&amp;callback=",symbol]; NSLog(@"URL IS: %@", searchURL...

How to get the sender's name of an NSButton

I have several NSButtons that are attached to a single IBAction. I need to differentiate inside the method between the different buttons. I tried the following, but it doesn't work: for (int i = 0; i++; i < 7) { if (sender == [NSString stringWithFormat:@"button%i", i+1]) { NSLog(@"sender is button %i", i+1); } } H...

Add spaces between words in spaceless string

I'm on OS X, and in objective-c I'm trying to convert for example, "Bobateagreenapple" into "Bob ate a green apple" Is there any way to do this efficiently? Would something involving a spell checker work? EDIT: Just some extra information: I'm attempting to build something that takes some misformatted text (for example, text copy ...