nsstring

How to cut out parts of NSString?

I have a lot of strings looking like this: @"/News/some news text/" @"/News/some other news text/" @"/About/Some about text/" @"/Abcdefg/Some abcdefg text/some more abcdefg text" How do I cut out the first part of the strings, so that I end up with the following strings?: @"/News/" @"/News/" @"/About/" @"/Abcdefg/" tia ...

How do I get a formatted NSString from format and va_list?

I'm developing a static library that will be distributed to other developers, who may need debug statements. So I have several levels of logging. In order to avoid constant appearance of if(loggingLevelCurrentlySet >= loggingLevelWantedForThisInstance){ NSLog(@"log this"); } I created a set of logging function wrappers. A simp...

How to populate 3 text fields with 3 different ViewController?

Hi I have the following situation: 1) On the main ViewController, I have 3 UITextFields. The user can fill them with keyboard or choose values from 3 ViewsController, which have a Picker to choose from values; 2) Now, I can declare 3 NSString in the main View Controller (obviously with @property(retain, nonatomic) so that they are to ...

stringWithFormat: with unknown datatype

I am making a framework and I have this code (conditions is an NSDictionary): for (NSString *key in conditions) { id value = [[conditions valueForKey:key] retain]; // Check if number or string if ([value class] == [NSString class]) { conditionsString = [NSString stringWithFormat:@"%@='%@' ", key, value]; } else {...

How to sort an array of objects by their NSString property

I have an array of custom objects. One of the properties of these objects is an NSString. I want to sort by that property. Because it is an NSString and not an NSNumber sorting is a little more difficult. Is there some kind of class method to help in this case? How should it be done? ...

NSRange freezing app

NSString *originalString = entriesResultStr; NSRange jarvisRange = [originalString rangeOfString:@"favoriteCount"]; NSString* substring = [originalString substringToIndex:jarvisRange.location]; For some reason, when I use NSRange, my app window won't open, but when I comment it out, my app opens fine. Any ideas? ...

Accessing string within an array within a plist iphone

I have a plist with root of type dictionary containing keys of type array, and each array has three items of type string. I want to access the strings and pass them to a view controller. This line is successful in my cellForRowAtIndexPath NSLog(@"Strings from plist: %@", [[self.aDictionary objectForKey:(@"%@",[self.keys objectAtIndex...

Problem using NSString compare:options:range, conflicting results

Ohh, what is wrong with this code !?!?! NSString *s1 = @"5 Oct 2010 18:30"; NSString *s2 = @"5 Oct 2010 09:47"; NSRange range = {0, 11}; // Both "D MMM YYYY " and "DD MMM YYYY" NSComparisonResult result = 0; result = [s1 compare:s2 options:NSLiteralSearch range:range]; // result == -1 NSString *sa = [s1 subst...

Re-encoding a NSString returns null

So I have this piece of code : if ([receivedPage hasPrefix:[NSString stringWithUTF8String:"\xC3\xAF\xC2\xBB\xC2\xBF"]]) // UTF-8 BOM 'EF BB BF' as UTF-16 chars { //DebugLog(@"converting calls list to UTF8"); receivedPage = [[[NSString alloc] initWithData:[receivedPage dataUsingEncoding:NSISOLatin1StringEncoding] enco...

Cannot pass string through classes

//Initialize the detail view controller and display it. OrderDetailsView *dvController = [[OrderDetailsView alloc] initWithNibName:@"OrderDetailsView" bundle:[NSBundle mainBundle]]; dvController.selectedOrder = (@"%@",selectedOrder); [self.navigationController pushViewController:dvController animated:YES]; [dvController release]; dvContr...

LocationManger use empty string for Latitude and logitude

hello guys, i am using the locationManager. I get the error "system.invaildCastexception" cause i fill my NSString lat and lng with (null). I want to fill them with nothing. how can i fill my NSString with nothing. lat=[[NSString alloc] initWithString:@""]; does not work. Best Regards ...

How do you remove extra empty space in NSString?

Hi, is there a simple way to remove the extra spaces in a string? ie like... NSString *str = @"this string has extra empty spaces"; result should be: NSString *str = @"this string has extra empty spaces"; Thanks! ...

Add each item into string

//Parse this shit //Create array of all items in order (with submatches still NSString *myregex1 = @"\\<([a-z0-9]+)\\sref\=\"([^\"]*)\">([^\<]*)\\<\\/\\1\>"; //Get all items in an array NSArray *items = [stringReply componentsMatchedByRegex:myregex1]; //Create string to hold all items in NSString *AllOrderItems; if ([items count] > ...

Best way to download a website

Hey. I am currently using [NSString stringWithContentsOfURL:url] to download the contents of an external webpage to my app. Is there any other way that might be faster or better/safer? ...

Parse NSDictionary to a string with custom separators

Hey! I have an NSMutableDictionary with some values in it, and I need to join the keys and values into a string, so > name = Fred > password = cakeismyfavoritefood > email = [email protected] becomes name=Fred&password=cakeismyfavoritefood&[email protected] How can I do this? Is there a way to join NSDictionaries i...

Adding items to string not showing characters

for (NSString *item in items) { NSString *ref = [item stringByMatching:myregex1 capture:2]; NSString *value = [item stringByMatching:myregex1 capture:3]; NSLog(@"%@ : %@", ref, value); AllOrderItems = [AllOrderItems stringByAppendingFormat:(@"%@: %@ \r\n", ref, value)]; } the AllOrderItem...

Object changes from NSMutableArray to NSData to NSString

I have a program which works normally. Then I downloaded some code from http://github.com/matej/MBProgressHUD to show a progress meter when doing something. This is the code that makes the progress meter pop up. [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES]; This will show a progress meter while...

NSString get -characters

I want to get the characters of an NSString. Like this: NSString *data; const char * typein = [[data characters] UTF8String]; But obviously NSString won't respond to -characters. How do I get the characters of NSString? thanks, Elijah ...

convert .zip file into NSData

Hey, Is it correct to initialize an NSData with a zip file? I want to convert a zip file into NSData and construct another file with the data (in simple language 'copy it'). I have the code as: NSURL *theFileUrl = [NSURL URLWithString: @"file://localhost/Users/xxx/Desktop/testZippedFile.zip"]; NSData *data = [NSData dataWithContentsOfU...

NSString with Instance Variable

So, I want to put an instance variable into a NSString like this: NSString *theAnswer = (@"The answer is %@\n", self.answer); I'm not sure am I right or not. I thought that NSString would work like NSLog but apparently it doesn't. theAnswer returns as only the instance variable without "The answer is" Can someone tell me why and h...