nsstring

objective-c "mutating method sent to immutable object" error

Hi guys, I'm pretty new to objective-c and try to create a small app for the iphone. I'm nearly done beside this little error here. Actually, I've searched hours with google to find a proper solution but unfortunately I'm not able to find a solution which works. I'm using this tutorial here to build up an UITableView: UITableView Tutori...

Objective-C NSString: strange characters when logging

Hey all, I'm a total noob when it comes to Objective-C / iPhone development. I'm trying to pull in text from a SQLite DB. I have a while loop that looks like this: while(sqlite3_step(selectstmt) == SQLITE_ROW) { And within that loop, this prints to the log just fine: NSLog(@"Text: %s",sqlite3_column_text(selectstmt, 1)); This does...

NSString - Convert to pure alphabet only (i.e. remove accents+punctuation)

I'm trying to compare names without any punctuation, spaces, accents etc. At the moment I am doing the following: -(NSString*) prepareString:(NSString*)a { //remove any accents and punctuation; a=[[[NSString alloc] initWithData:[a dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES] encoding:NSASCIIStringEncoding] a...

Preserve ` ` in NSString?

I want to preserve the entry of   in an iPhone application text field. However, logging and subsequent viewing of the UItextField suggest this string is getting turned into a plain old space... When I add &nbsp to the text field, it goes as single characters until the final semicolon, at which point it disappears from the log mess...

NSString to cString UTF-8 conversion problem

Hi there, I'm having strange encoding issue converting NSString to UTF8 cString. I'm fetching XML data from webserver. XML is correctly encoded with UTF-8 encoding. After fetching data, I convert it to NSString as follows: NSString *XMLdata = [[[NSString alloc] initWithData: receivedData encoding: NSUTF8StringEncoding] autorelease]; ...

NSString to FSRef conversion doesn't work

Hi, For my app I need to use the Carbon file manager API to get the size of a folder (NSEnumerator is slow, and using NSTask with a shell command is even worse). I've imported the Carbon framework, and I'm using this method to get the size of a folder: http://www.cocoabuilder.com/archive/message/cocoa/2005/5/20/136503 It uses an FSRef...

NSString @"\" adding backslash character objective-c

Does anyone know of an easy way to add a single backslash "\" to a NSString in Objective-C? I am trying to have a NSString *temp = @"\/Date(100034234)\/"; I am able to get a double backslash or no backslash, but unable to get a single backslash. Any help would be appreciated. Thanks ...

How to make an NSString path (file name) safe

Hi, I'm using very tricky fighting methods :) to make a string like 'Fi?le*/ Name' safe for using as a file name like 'File_Name'. I'm sure there is a cocoa way to convert it. And I'm sure the best place to ask is here :) Thank you! ...

How do I convert NSString to NSData?

I have this line of code to convert NSString to NSData: NSData *data = [NSData dataWithBytes:[message UTF8String] length:[message lengthOfBytesUsingEncoding:NSUTF8StringEncoding]]; How do I do this in Unicode instead of UTF8? My message may contain cyrillic characters or diacritical marks. ...

Wifi vs. Edge/3G and componentsSeparatedByString (NSString)

Hi, does anybody has a clue why downloaded html code via Wifi is different from the same url's content using Edge/3G? I noticed it when using the function because the output from Wifi has much more lines than the output from 3G. Analyzing the code I could see that only a few line breaks were detected. Here is the code: NSString *htmlC...

Cocoa String Question

I have a NSString and I want to write its value to a NSMutableString. Is this valid: NSString *temp = [NSString stringWithString:@"test"]; NSMutableString *mutable = temp; I ask because although this seems doable, I would think that this would assign both temp and mutable to the same address space. I have this question a lot when pa...

iphone how to check that a string is numeric only

HI , i am getting a string input from a UITextField i want to check that this string in numeric . how i will do that .. (numeric can have decimal points also) . how to do that ? ...

How to get count of Unique chars in a string

How can I get the number of unique chars in my String? Ex: NSString *myString = @"Hello"; I want the count to be 4 and not 5. I was trying to use the NSCharacterSet of myString and get the count but seems like it doesnt work. NSCharacterSet *myCharSet = [NSCharacterSet characterSetWithCharactersInString:myString]; [myCharSet count]...

Accessing NSString properties of a Core Data entity

I'm moving my initial steps in the Core Data realm (and I'm quite new to iPhone development, too) and I found a behavior I cannot explain. I declared a subclass of a NSManagedObject and defined a few properties, some of them of type NSString *, MyObject.h is something like: @interface MyObject : NSManagedObject { } @property (nonatomi...

Generating a String from CLLocationDegrees, e.g. in NSLog or StringWithFormat.

Hello Stacked-Experts! My question: How to generate a string from a CLLocationDegrees value? Failed attempts: 1. NSLog(@"Value: %f", currentLocation.coordinate.latitude); //Tried with all NSLog specifiers. 2. NSNumber *tmp = [[NSNumber alloc] initWithDouble:currentLocation.coordinate.latitude]; 3. NSString *tmp = [[NSString alloc] ini...

Using The value of an NSString variable to manipulate the object the the name refers to.

I have a bunch of images on the screen.... UIImageView *s1, s2 ,s3 etc up to *s10 Now suppose I want to update the image each displays to the same image. Rather than doing s1.image = sampleimage; s2.image = sampleimage; : s10.image = sampleimage; How could i write a for loop to go from 1 to 10 and then use the loop var as part of the l...

Setter for NSString, how is it working?

This question follows on from a previous question, that has raised a further issue. What I am trying to understand is just when the pointers and object in this example are being created and what ultimately happens to them. I am still trying to get my head round this, so please excuse any false assumptions I may have made. // MAIN int ma...

Why is my sizeWithFont:constrainedToSize:lineBreakMode: always returning zero?

I'm trying to make a UITableViewCell that adjusts its height based on the length of a string it's displaying, but am getting hung up on this method. Here's what I've got: NSString *text = @"A really long string in here"; CGSize theSize = [text sizeWithFont:[UIFont boldSystemFontOfSize:18.0f] constrainedToSize:CGSizeMake(265.0f, MAXFLOA...

NSString to NSDate

I got a string that contains the current date by using this : NSString *date = [[NSDate date] description]; At a different point I am want to retrieve the date from this string and I use the following code [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; NSDateFormatter *dateFormatter = [[NSDateFormatter...

Trying to Write NSString sha1 function, but it's returning null

I have the following Objective-C function: +(NSString *)stringToSha1:(NSString *)str{ NSMutableData *dataToHash = [[NSMutableData alloc] init]; [dataToHash appendData:[str dataUsingEncoding:NSUTF8StringEncoding]]; unsigned char hashBytes[CC_SHA1_DIGEST_LENGTH]; CC_SHA1([dataToHash bytes], [dataToHash length], hashBytes)...