我有字符串问题。字符串显示:~00000000:termometr2: +26.9 st.C
我想在textfield.text中仅使用此部分:+26.9 st.C
。
由于
答案 0 :(得分:3)
NSString *fullStr = @"00000000:termometr2: +26.9 st.C";
NSArray *parts = [fullStr componentsSeparatedByString:@" "];
textField.text =[NSString stringWithFormat:@"%@",[parts objectAtIndex:1]];
答案 1 :(得分:2)
它可能对你有帮助:
NSArray *_array = [yourString componentsSeparatedByString:@":"];
[myTextField setText:[_array lastObject]]; // or any other component you want
答案 2 :(得分:0)
只需这样做,使用方法 stringByReplacingOccurrencesOfString:withString::
NSString *originalString = @"~00000000:termometr2: +26.9 st.C";
NSString *filteredString = [originalString stringByReplacingOccurrencesOfString:@"~00000000:termometr2: " withString:@""];