PDA

View Full Version : Change spaces to plus signs? - Cocoa




macindev
Jul 30, 2009, 01:00 AM
I have no clue how to do this!
What I want to be done is to have the spaces in a string be changed to plus "+" signs, but I don't know what code would be needed. Can anyone help?
Thanks in advance.


For those who want to know, here's my code:

- (void)connectSearch:(id)sender{
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:
[@"http://www.google.com/search?q=" stringByAppendingString:[searchQuery stringValue]]]]];
}



gnasher729
Jul 30, 2009, 01:46 AM
I have no clue how to do this!
What I want to be done is to have the spaces in a string be changed to plus "+" signs, but I don't know what code would be needed. Can anyone help?
Thanks in advance.


For those who want to know, here's my code:

- (void)connectSearch:(id)sender{
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:
[@"http://www.google.com/search?q=" stringByAppendingString:[searchQuery stringValue]]]]];
}


In XCode, right-click on the word "stringByAppendingString", select "Show in API Reference" in the popup menu, and read the documentation of the NSString functions.

macindev
Jul 30, 2009, 03:12 AM
Thank You! I finally got it to work using this

stringByReplacingOccurrencesOfString:(NSString *)replaceString withString:(NSString *)replaceStringWith
:D