tags:

views:

32

answers:

2

hi all, i hv a question.

my url is some thing like this

http://www.google.com?to=shishir&from=friend

and i hv 2 textfeild from where i m getting value of to and from.

i need to set those values of 2 textfeiilds into the URL to="values from textfeild" from="value from textfeild"

to create a somewhat called a dynamic URL.

how can i do it

quick reply is always appreciated

regards shishir

A: 

Quick and dirty could be:

  1. get the text into 2 arrays.
  2. 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.

Ankur Chauhan
this where also,i want to put values into URLNSURL *url = [NSURL URLWithString:@"http://www.google.com/a?to="valueshere"help.always appreciated regards
shishir.bobby
+2  A: 

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];
Vladimir
this one is showing error sayingtoo many arguments.....suggestionsregardsshishir
shishir.bobby
sorry, had a typo in a code. must be ok now
Vladimir