objective-c: Extremely Strange and annoying string problem
i've been working on a tableview program and i have a function that processes several data from user preferences, and core-data. the program parses these things and returns a url adress. heres the code:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *serverAdress = [prefs stringForKey:@"serverAdress"];
serverAdress = [serverAdress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd.MM.yyyy"];
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
[dateFormatter2 setDateFormat:@"dd.MM.yyyy HH:mm"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
NSString *dateTimeString = [NSString stringWithFormat:@"%@ %@",dateString,[dashboardParameters attribute1]];
NSTimeInterval dayInterval = [[dashboardParameters attribute2] intValue]*60*60*(-1);
NSDate *date2 = [[dateFormatter2 dateFromString:dateTimeString] addTimeInterval:dayInterval];
NSString *urlString =
[NSMutableString stringWithFormat:@"%@/webservices/service1.asmx/getHourlySales2?tarih2=%@&tarih1=%@&salesType=%@",
serverAdress,
dateTimeString,
[dateFormatter2 stringFromDate:date2],
[dashboardParameters itemOrder]
];
urlStri开发者_运维百科ng = [urlString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
return urlString;
Everything works great, i have no problem on retrieving data. But when i execute the code, i get this log output:
//server.dyndns.org/webservices/service1.asmx/getHourlySales2?tarih2=20.01.2011%2016:00&tarih1=19.01.2011%2016:00&salesType=Hepsi/webservices/service1.asmx/getHourlySales2?tarih2=21.01.2011%2022:00&tarih1=21.01.2011%2011:00&salesType=Hepsi
it has to be
//server.dyndns.org/webservices/service1.asmx/getHourlySales2?tarih2=20.01.2011%2016:00&tarih1=19.01.2011%2016:00&salesType=Hepsi
But strangely the program adds
/webservices/service1.asmx/getHourlySales2?tarih2=21.01.2011%2022:00&tarih1=21.01.2011%2011:00&salesType=Hepsi
by itself after the normal processing.
Also another important thing, the code runs normally when i remove
NSString *serverAdress = [prefs stringForKey:@"serverAdress"]
from the code and enter serveradress manually.
Plase help , everything in the program works fine but im stuck with this problem.
Thanks for helping.
So what's in serverAdress before you add it to urlString. Looks as if serverAdress contains '//server.dyndns.org/webservices/service1.asmx/getHourlySales2?tarih2=20.01.2011%2016:00&tarih1=19.01.2011%2016:00&salesType=Hepsi'
精彩评论