View Full Version : Need help with string concatenation please
guyddor
Aug 3, 2009, 03:26 PM
Hi,
I want to develop an app that will take the value from UITextField and use it
in a url like that:
http://www. the value from UITextField .com/
How do I do that?
dejo
Aug 3, 2009, 03:29 PM
Use NSString's stringByAppendingString: or stringByAppendingFormat:
zrbecker
Aug 3, 2009, 08:45 PM
This should work.
NSString urlString = [NSString stringWithFormat:"http://www.%@.com/", myUITextBox.text];
moral-hazard
Aug 4, 2009, 12:05 AM
This should work.
NSString *urlString = [NSString stringWithFormat:"http://www.%@.com/", myUITextBox.text];
I'll second this approach (with the minor correction I added :p). +stringWithFormat is good because it gives you an autoreleased string.
guyddor
Aug 4, 2009, 03:05 PM
The button get stuck
What to do?
dejo
Aug 4, 2009, 03:30 PM
What to do?
Explain the issue in more detail. Like, what do you mean the button got "stuck"? Any errors or warning, run-time or build? Perhaps include the button-action code...
guyddor
Aug 4, 2009, 04:15 PM
Look at the attachment file
dejo
Aug 4, 2009, 05:18 PM
Perhaps include the button-action code...
Restated.
moral-hazard
Aug 4, 2009, 06:57 PM
Your program appears to be crashing. Check the stack trace. I've only seen buttons get stuck like that on a crash.
guyddor
Aug 5, 2009, 12:30 AM
What to do?
Edit:
I got 2 warnings:
-passing argument 1 of 'stringWithFormat': from incompatible pointer type
-unused variable 'urlString'
dejo
Aug 5, 2009, 12:36 AM
What to do?
Keep asking for help without providing any code? ;)
guyddor
Aug 5, 2009, 01:14 AM
#import "MainView.h"
@implementation MainView
- (IBAction)searchGoogle {
NSString *urlString = [NSString stringWithFormat:"http://www.%@.com/", userTextField.text];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
@end
What to do?
This is the only code that I have in my project
dejo
Aug 5, 2009, 09:59 AM
What to do?
Two things.
1) You need to prefix your string with the @ character for Objective-C to treat it as a constant NSString object.
NSString *urlString = [NSString stringWithFormat:@"http://www.%@.com/", userTextField.text];
2) Use [ code ] tags rather than quotes.
guyddor
Aug 5, 2009, 10:59 AM
warning: unused variable 'urlString'
What should I do?
dejo
Aug 5, 2009, 11:29 AM
What should I do?
Step away from the real coding, go (re)learn the basics of Objective-C and iPhone dev before you continue. Also, it helps to post specific questions rather than generic ones like "What should I do?" Hope that helps.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.