nsstring

make array out of string with variable number of spaces in Objective-C

This is the code that I would use if it was always single spaces in between words. Since I have multiple spaces in between some words how can my code be changed to remove the extra spaces when using componentsSeparatedBySring. I'm new to OBjective-C so any help would be greatly appreciated! Here is my code: NSString *myString = @"One Tw...

Get the a part of content from NSString

Hi, everyone, I want to ask something about the NSString in objective C. I use the following code to retrieve some of the HTML content. NSHTTPURLResponse *response = nil; NSError *error = nil; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; NSString *data = [[NSString ...

Cocoa - Remove All Chars Before and Including Substring from String

Hi all, getting myself confused with NSString's various range methods and where and when they should be used. I have a random string. Somewhere in the string it may (or may not) contain an identifier such as "Customer Name:" (the quotes will not be included.) Problem: I need a new string where everything up to and including "Customer N...

Cocoa - Trim all leading whitespace from NSString

Hi all, (have searched, but not been able to find a simple solution to this one either here, or in Cocoa docs) Q. How can I trim all leading whitespace only from an NSString? (i.e. leaving any other whitespace intact.) Unfortunately, for my purposes, NSString's stringByTrimmingCharactersInSet method works on both leading and trailing...

How to clean spaces in a NSString

Hi, I would like to reduce the number of spaces between two words in a NSString (Objective-C/iPhone dev) to only one. Do you know some method that could do that ? Exemple : Before cleaning : "Hi,       my   name       is                Tom." After cleaning : "Hi, my name is Tom." Thanks ...

Objective C string manipulation, peeking, adding to

Hi, I am trying to manipulate a string of open hours that is given to me. It is poorly formatted and I need to bring it up to the same standard as another piece of data from a different source. Mon-Wed 930-1700 Thu 900-1700 Fri 930-1700 Mon - Wed 930-1700 Thu 900-1700 Fri 930-1700 Mon - Thu 930-1600 Fri 930-1700 Mon - Wed 930-1700 Thu...

How to convert to unicode from a char array with an intermediate null charaters

i used + (id)stringWithCString:mycharaters encoding:NSUnicodeStringEncoding mycharaters is a char array with an intermediate null charaters and end with two null charaters. char mycharaters[20]; it contains a unicode string and i want to show it. but "The array must end with a NULL character; intermediate NULL characters are not allo...

Objective C Memory Management Woes

I know this has been discussed ad-nauseum but I just don't get some of the memory management. I understand that retain keeps the object alive and copy gives one a separate copy of an object. What I don't get is when it comes to ivars & properties, retain as a property means that the setter releases the old value & retains the new: prop...

calling [myString release] does NOT decrement [myString retainCount]...

I have the following situation, which seems to cause my iPad application to leak memory. I have a class with a string property... @property(nonatomic,retain) NSString * synopsis; I set the string property from some HTTP response, either from JSON or XML response. At that point the retain count of the synopsis object is 1. But I have...

stringByTrimmingCharactersInSet: message not working

Hi, It is exasperating but I can't get this code work, first I though it was a mutable/inmutable problem but it doesn't, I believe. What am I doing wrong? labeledPemString do has contents and the specified characterSet is printing 'ranges begin {0, 26}' . But unlabeledBeginPemString has the same as the original string. //Get the .pe...

NSString stringWithUTF8String appending error

I'm trying to append a char array to an NSString. When I use the code below, I get this error: * initialization method -initWithCharactersNoCopy:length:freeWhenDone: cannot be sent to an abstract object of class NSCFString: Create a concrete instance! What does this mean and how can it be fixed? NSString *str = [[NSString new] initW...

24hr to 12hr time convert, insert character to string

This is sort of a secondary question to my question here but it was suggested split the questions up for a better response. I have individual lines of data like the following that a passed to the function separately. Mon-Wed 930-1700 Thu 900-1700 Fri 930-1700 Mon-Wed 930-1700 Thu 900-1700 Fri 930-1700 Sat 900-1200, Home Lending Sat ...

iphone variable in NSString

I need to define a string that will include a string that changes (i can already make that string change) and additional text. for example, NSString *commentsAddress = *somestring*/#comments; now i know it sould be something more along the lines of NSString *commentsAddress = @"%@/#comments", *somestring*; but I can't get this to...

Case insensitive compare against bunch of strings.

Hi, What would be the best method to compare an NSString to a bunch of other strings case insensitive? If it is one of the strings then the method should return YES, otherwise NO. ...

NSString fails, app crashes trying to NSLog the NSError

What it says on the tin. All I want to do is save an NSString to a .txt file in my Documents directory so it can be accessed by the user. This is called in applicationWillTerminate: NSError* err; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths object...

How can I use NSString between classes?

Hi, I have two classes, Class A and Class B, both of them are subclasses of UIViewController. I class A I have an NSString and I want to use this NSString in class B. ClassA.h: @class ClassB; @interface ClassA : UIViewController { ClassB *classB; NSString stringA; } @property (nonatomic, retain) ClassB *classB; @property (nonat...

iphone NSString Array

Hi, I declared NSString *dayinfield[43]; and fill it in -(void)DrawDemo { dayinfield[2] = @"hallo"; dayinfield[3] = @"test"; // also i can read it NSLog (@"show: %@",dayinfield[2]); //works fine } but when i like to read its content in another function (same class) -(void)ReadData { NSLog (@"show: %@",dayinfield[2]); // I get ...

Range of substring in string.

Hi, Is the a way to get the NSRange of an NSString in an NSString? ...

In objective-C, I have a NSString with one letter in it. How can I get the ASCII value of that letter?

for example: NSString *foo = @"a"; How can I get the ASCII value of this? (I know it is really 97, but how can I get it using Objective-C?) I guess I can convert it to char but I had no luck with that so far. Sorry for being too nooby! ...

NSDate from NSString

I have a string in the format "Fri Jul 09 17:57:44 +0000 2010" which I need to convert to an NSDate. I have tried a few unsuccessful operations to convert this date, and was wondering if anyone could tell me how I can achieve this. Regards ...