pass value through url
I have a question.
my URL is some thing like this
http://www.google.com?to=shishir&from=friend
and I have 2 textfields from where I`m getting value of to and from.
I need to set those values of 2 textfields into the URL to="values from textfield" from="va开发者_如何转开发lue from textfield"
to create a somewhat called a dynamic URL.
how can i do it
quick reply is always appreciated
regards shishir
You can use NSString's +stringWithFormat
method to create your string:
NSString* urlString = [NSString stringWithFormat:@"http://www.google.com?to=%@&from=%@", field1.text, field2.text];
Quick and dirty could be:
- get the text into 2 arrays.
- sprintf to the final string variable.
char* from;
char* to;
char* url; // string of the final URL
sprintf(url, "http://www.google.com?from=%s&to=%s", from, to);
This should do the trick as needed, obviously you may need to do the magic to get the content of the from and to strings in the pointers and allocate memory to url, but other than that I guess, this takes care of the issue.
精彩评论