nsstring

Convert NSString to NSNumber

Hi, i get a nsstring from a nsdictionary via: inputString = [dataUsage valueForKey:@"amount"]; after that the string looks like: 23,56 how can i convert this string into a nsnumber? i have tried the following: NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterDecimalStyle];...

iPhone: Find UITableViewCell using a UILabel

I have a UITableView that has about 20 cells. Each has a UILabel within, and I need to search and find the cell that has the label @"Test". Is there a way to loop through the cells and search for the NSString @"Test"? ...

Displaying content at correct scale in UIWebView on iPad

I have a UIWebView set to scale to fit in an iPad app that gets its content from and NSString. If I turn off scale to fit the text is bigger, although would like it to be much bigger, but I lose the zooming feature. If I set scale to fit on the text is very small as it is obviously scaling the lot to fit the page...and I get zooming ba...

Measuring NSString lines, words, etc

Hi, I am trying to calculate the closest text position in a string (text of UITextView) from a CGPoint. I wonder if some methods in NSString are useful for this? I would appreciate a good explanation of the following methods. Because I think they are useful here. I read the docs but I don't really understand what they do ;( NSString i...

How to do comparison Check through multiple NSString with objects

Hi, I am having difficulties with some logic. What I am trying to do is I have a nsmutablearray which I want to do a check with an object. If i have selected multiple creditcards in a particular view i store that card details name is my nsmutablearray called filteredCard. Then I have objects of companies which has one or more creditcard...

Shuffling Letters in an NSString in Objective-C

I have written this function which shuffles the contents of a NSString, and it seems to work, but every now and then it crashes. This may be a roundabout way, but I put the characters into an array, swap the elements in the array randomly, and then turn the array back into a string. I'm not sure what I am doing that is unsafe which make...

Objective C try parse boolean

I would like to know how, in Objective-C, how to tell if a string represents a boolean value. The [string boolValue] method will not work, because when I try to parse a string like [@"ERROR" boolValue] it returns NO instead of throwing an exception. In C#, I could do something like: if (Boolean.TryParse(string, out bool)), but this is no...

Get parts of a NSUrl in objective-c for iPhone

I have an NSString with the value of http://digg.com/news/business/24hr How can I get everything before the 3rd level? http://digg.com/news/ ...

Adding a line break to a UITextView

Hi I have a UITextView that takes an NSString with formating stringWithUTF8String. It is getting its values from a database and I want the text in the database to be rendered with breaks within the text. I tried using "\n" to do this but it gets rendered as text. Doing this in my information page of the app as straight text worked but I...

NSArray from NSString (in plist format)

Hi there. I use NSURLConnection to get the contents of a plist file from a remote server. On connection:didRecieveData: I add the latest data to an NSMutableString. Now my problem is adding this data to an array. So you have arrayWithContentsOfURL - which is synchronous - but i suppose I could just add the contents of the NSString to ...

Understanding NSString comparison in Objective-C

Both the following resolve to True: 1) @"foo" == @"foo" (is True) 2) NSString *myString1 = @"foo"; NSString *myString2 = @"foo"; myString1 == myString2 (is True) However, there are definitely times where two NSStrings cannot be compared using the equality operator, and [myString1 isEqualToString:myString2] is required instead. Ca...

NSString to 64bit integer converstion on iPhone

Hi! I am struggling with very simple thing: I receive some ids by http request as a string. I know they represent 64bit integer id numbers. How can I convert them to the 64 bit Integers (NSNumber or NSInteger)? Functions like: [nsstring integerValue], [nsstring intValue] seems to be 32bit limited (max value:2147483647). Any Hints? ...

Receiving complete message from TCP socket

Hi, I read data from a TCP socket connection, but the server sends me \0 from time to time (which would mark the end of a message). Thus, I do not get the rest of the message. I read like this: uint8_t buf[tcpBufferSize]; unsigned int len = 0; len = [inputStream read:buf maxLength:tcpBufferSize]; if(len > 0) { NSMutableData* dat...

Cocoa - Insert text between tags

Hello, I was wondering how it is possible to insert text between HTML tags in Cocoa. I am displaying source code in a NSTextView - example: <html> <head> <title>test</title> </head> <body>hello!</body> </html> The code above can vary in size, but what should I do if I wanted to insert say <link rel="apple-touch-icon" href="webclip.pn...

Include a '%' in an NSString?

How can I include a percent symbol (%) in my NSString? [NSString stringWithFormat:@"Downloading (%1.0%)", percentage] The above code does not include the last percent in the string. ...

Combine string in objectivec

How do I concenate 2 strings in objective-c, like in VB.net you can just do "foo" & "bar" ...

HTML and NSString

I use the youtube api to get descriptions from videos but sometimes not the full description shows up becuase of a @amp; how do I fix this? BTW I use NSXMLParser. ...

@"" string type literals for NSNumber

I love the shorthand handling of string literals in Objective C with the @"string" notation. Is there any way to get similar behavior with NSNumbers? I deal with numbers more and it's so tedious having [NSNumber numberWithWhatever:] calls everywhere. Even creating a macro would work, but my knowledge of how best to do that is limited. ...

NSString's method doubleValue gives unexpected results

Hi, I have a need to convert NSString to double. If this string is in essence integer, then result is OK. If string is decimal, perhaps also with group separators then results are false. Any king of separator (whether "." or ",") whis is first in the string is always used as decimal separator. I have tried to do something with NSScanne...

NSString leaking even with release at the right place (I guess) ?

Hi there, When I analyze the following code with Instruments, it reports a leak on variable imageName: //loadImagesFromPotatoesIndexesArray -(void) loadImagesFromPotatoesIndexesArray{ //Load Textures from Disk textures = [[NSMutableArray alloc] init]; //NSArray *masks = [[NSArray alloc] initWithArray:mainDelegate.masksArray...