有問題。這裏是我的代碼:stringByReplacingOccurrencesOfString不按預期方式工作
Latitude = [TBXML textForElement:lat]; //Latitude & Longitude are both NSStrings
Longitude= [TBXML textForElement:lon];
NSLog(@"LAT:%@ LON:%@",Latitude,Longitude);
NSString *defaultURL = @"http://api.wxbug.net/getLiveWeatherRSS.aspx?ACode=000000000&lat=+&long=-&unittype=1";
newURL = [[defaultURL stringByReplacingOccurrencesOfString:@"+"
withString:Latitude]
stringByReplacingOccurrencesOfString:@"-"
withString:Longitude];
NSLog(@"%@",newURL);
而這裏的輸出:
LAT:-33.92 LON:18.42
http://api.wxbug.net/getLiveWeatherRSS.aspxACode=000000000&lat=18.4233.92&long=18.42&unittype=1
正如你可以看到,一些奇怪的事情正在發生的附加碼。我在這裏做錯了什麼?
謝謝,現在一切都清楚了。 :)我會照你的建議去做,並將佔位符更改爲更清晰的值。謝謝! – 2011-02-17 18:22:23