使用componentsSeparatedByString以#开头的NSString不起作用

问题描述 投票:-3回答:1

我的代码如下:

NSArray *modifyVersionOnDevice  [FileHandler parseFile:devicepath];
NSString *param = [modifyVersionOnDevice objectAtIndex:1];

//param at this point is one element with string of "#MAJREV: 3"

//As soon as I run the next line, I get an error Unrecognized selector sent 
to instance.

NSArray *d =[param componentsSeparatedByString:@":"];

如果我硬编码

NSString *param =@"#MAJREV: 3";  it works
objective-c nsstring
1个回答
-4
投票

事实证明你必须将param转换为文字字符串。

NSString *param = [NSString stringWithFormat:@"%@",[modifyVersionOnDevice objectAtIndex:1]];

然后NSArray * d = [param componentsSeparatedByString:@“:”];

© www.soinside.com 2019 - 2024. All rights reserved.