nsstring

How to convert from int to string in objective c: example code...

I am trying to convert from an int to a string but I am having trouble. I followed the execution through the debugger and the string 'myT' gets the value of 'sum' but the 'if' statement does not work correctly if the 'sum' is 10,11,12. Should I not be using a primitive int type to store the number? Also, both methods I tried (see comm...

WebPageContent problem

I have parsed some data from webpage content and stored it as an NSString. In that string there is a unicode character (\u0097). How can i remove or replace this and avoid all unicode characters? I tried using this line but it hasn't worked: [webpagecontent stringByReplacingOccurrencesOfString:@"\\u0097" withString:@" "]; Can anyone ...

Two Dimension NSMutableArray help?

Ok, I have some C# code that looks like this and I was wondering what other developers would recommend if I am trying to put this into Objective-C. List<List<string>> meta_data I'm planning on using NSMutableArray but how to exactly get that two-dimensional array figured out is my problem, since there is no such thing as a multidimens...

class variable accessible at end of one function, and crashes on access at beginning of next

(programming in iPhone objective-C) I have a class level NSString* that I create, add property(nonatomic,retain) and synthesize code for and I can modify the string endlessly with stringByAppendingString functions and display the string using NSLog just fine. All of this is done in a subclass, overridden viewDidLoad function. When I try...

iPhone Text Field

Hello, I have run into an issue that I have yet to be able to solve. Hopefully someone can help. I have an app that I am using to do simple calculations, some of the results are larger than the UItextField. Does anyone know how to limit the output to say 10 characters like say a calculator would using exponents. This is the code I am...

How to store a value of NSString as char array within a structure in Objective-C?

I am having trouble assigning the value of an NSString to a char * within a structure of a singleton class. The following is a simplification of my problem. My code utilizes more fields in the structure and passes more NSStrings. Say I have a singleton class "SingletonClass" with a structure (I've done my homework with the Apple Documen...

Remove all but numbers from NSString

I have an NSString (phone number) with some parenthesis and hyphens as some phone numbers are formatted. How would I remove all characters except numbers from the string? ...

NSData to NSString truncated - iPhone

I have the following code. NSData *pageData = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL]; NSString *webpage = [[NSString alloc] initWithData:pageData encoding:NSUTF8StringEncoding]; This works fine with most pages but truncates the really long ones, is there a way around this at all? ...

Convert first number in an NSString into an Integer?

I have an NSString like so: @"200hello" or @"0 something" What I would like to be able to do is take the first occuring number in the NSString and convert it into an int. So that @"200hello" would become int = 200. and @"0 something" would become int = 0. ...

text layout in custom rendered UITableViewCell

I am trying to custom render text within a UITableViewCell. This text can be over a number of lines and can contain http links, font and colour changes. I have looked at the sizeWithFont methods of NSString, but can't really work out a good way of rendering each part of the string so that it all runs together correctly. Do I need to r...

simple question concerning NSString adding multiple strings

I have a fairly simple question concerning NSString however it doesn't seem to do what I want. this is what i have NSString *title = [NSString stringWithformat: character.name, @"is the character"]; This is a line in my parser takes the charactername and inserts in into a plist , however it doesn't insert the @"is the character" ...

iphone sdk - Remove all characters except for numbers 0-9 from a string

OK So here's the plan. The XML I'm getting data from allows non-numeric text in phone number fields (for descriptions or contact names, etc). I am trying to extract only the numbers and call the tel: URL with them to initiate a call. Here's whats NOT working: NSCharacterSet *charset = [[NSCharacterSet decimalDigitCharacterSet] invertedS...

heightForRowAtIndexPath for longer NSStrings

I have a UITableView (Grouped!) and need to calculate the height of two styles of cells: UITableViewCellStyleDefault and UITableViewCellStyleValue2. This is how I do it for UITableViewCellStyleDefault: CGSize textSize = {300.f, 200000.0f}; CGSize size = [myTextString1 sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:tex...

How can I make unicode characters from integers?

I want to make an array of Unicode characters, but I don't know how to convert integers into a Unicode representation. Here's the code I have so far NSMutableArray *uniArray = [[NSMutableArray alloc] initWithCapacity:0]; int i; for (i = 32; i < 300; i++) { NSString *uniString = [NSString stringWithFormat:@"\u%04X", i]; [uniArray addO...

objective-C string encoding problem...

Ok, I'm fairly new to C sockets but I just need to do some simple sendto() and recvfrom() calls to get a string out across a network, using multicast sockets. After looking around and reading several guides (including Beej's), I found the code below which does the job of listening for messages sent over a multicast socket (which is what ...

Why am I getting an invalid NSString from SQLite for my UILabel?

I have a view with a UILabel and a UITableView. I'm using this code to get a string from a database: -(void)getOneQuestion:(int)flashcardId categoryID:(int)categoryId { flashCardText=[[NSString alloc] init]; flashCardAnswer=[[NSString alloc] init]; NSString *martialStr=[NSString stringWithFormat:@"%d", flashcardId]; ...

Storing and retrieving unsigned long long value to/from NSString

Hi I have an unsigned long long value which I want to store into an NSString and retrieve from the string. Initially I have the value in an NSNumber and I am using this to get the string NSString *numStr = [NSString stringWithFormat:@"%llu", [myNum unsignedLongLongValue]]; where myNum is an NSNumber. To get back the NSNumber from t...

Cocoa: Binding to an array of NSStrings which are stored in the application's preferences

OK, I'm feeling really REALLY stupid for asking this question, but I've managed to stump myself so hard that I doubt I have the proper detachment to figure out the answer for myself any more. My apologies in advance... I have been playing around with bindings for a while now and LOVE them. That and the KVO/KVC conventions built into O...

What's the proper way to wrap [NSString stringWithFormat:]?

Assume I have a method with the signature: + (NSString *) myFormattedString:(NSString *)format, ...; And I want it to prepend a string of my choice (e.g. @"Foo: "). I guess the best way is to use [myString initWithFormat:arguments:], but how would you implement this method? I tried doing the following, but I get the warning as spe...

iPhone Dev - NSString Creation

I'm really confused with NSStrings. Like when should I do NSString *aString = @"Hello"; of should it be: NSString *aString = [[NSString alloc] initWithString:@"Hello"]; But then its different when you're assigning a value to an NSString property isn't it? Can someone clear this up for me? Thanks!! ...