0

我的字符串有问题。字符串显示:~00000000:termometr2: +26.9 st.C我只想使用这部分:+26.9 st.C在我的 textfield.text 中。

谢谢

4

3 回答 3

3
NSString *fullStr = @"00000000:termometr2: +26.9 st.C";
NSArray *parts = [fullStr componentsSeparatedByString:@" "];
textField.text =[NSString stringWithFormat:@"%@",[parts objectAtIndex:1]];
于 2012-07-19T15:13:38.773 回答
2

它可能会帮助您:

NSArray *_array = [yourString componentsSeparatedByString:@":"];
[myTextField setText:[_array lastObject]]; // or any other component you want
于 2012-07-19T15:14:58.750 回答
0

只需这样做,使用方法stringByReplacingOccurrencesOfString: withString:

NSString *originalString = @"~00000000:termometr2: +26.9 st.C";
NSString *filteredString = [originalString stringByReplacingOccurrencesOfString:@"~00000000:termometr2: " withString:@""];
于 2012-07-19T15:12:53.453 回答