2010-09-09 129 views
0

我用座標填充字符串,這工作正常。 但我怎樣才能刪除這個字符串的內容。刪除字符串內容

PS:我在Web服務中使用這個字符串。 Web服務接受字符串並將其轉換爲typ double。

如果我讓lat = nil;它劑量工作。

這裏的代碼:

double degreesLat = newLocation.coordinate.latitude; 
lat = [NSString stringWithFormat:@"%1.4f",degreesLat]; 

回答

0
lat = @""; 

會工作,如果你只是想設置該字符串爲空白。

+0

感謝您的快速回復。我嘗試過,但我沒有工作。我會嘗試一些在web服務中。 – user389431 2010-09-09 19:57:09

0

NSString是不可變的;你不能在示例代碼中更改lat指向的NSString的內容。您可以更改lat指向的NSString實例。例如,你可以這樣做:

lat = @""; // sets lat to an empty string 

如果你想LAT是一個字符串,它可以讓你改變它的價值,你可以使用NSMutableString

+0

但沒有我得到警告「不兼容的Objective-C類型分配'結構NSString',期望結構NSMutableString'.h代碼\t NSMutableString * lat; \t @property(nonatomic,retain)NSMutableString * lat;和在.m文件\t雙degreesLat = newLocation.coordinate.latitude; \t LAT = [的NSMutableString stringWithFormat:@ 「%1.4F」,degreesLat]; – user389431 2010-09-09 20:08:01

+0

我得到它,這樣它的工作\t \t LAT = [[的NSMutableString。 alloc] initWithString:@「」]; – user389431 2010-09-09 20:18:23