所以听起来你想要单独的字符串中的 x、y、z 和 t 值?你把它们放在一个大串里?如果您需要帮助,请尽量说得更清楚,但这应该让您朝着正确的方向开始:
NSString *yourNSString = @"Variable1 = x;\n Variable2 = y;\n variable3 = z;\n variable4 = t";
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"=;"];
NSArray *splitter = [yourNSString componentsSeparatedByCharactersInSet:set];
NSString *x;
NSString *y;
NSString *z;
NSString *t;
for(int i = 0; i<splitter.count ; i++)
{
if(i==1)
{
x = [[splitter objectAtIndex:i]stringByReplacingOccurrencesOfString:@" " withString:@""];
}
else if(i==3)
{
y = [[splitter objectAtIndex:i]stringByReplacingOccurrencesOfString:@" " withString:@""];
}
else if(i==5)
{
z = [[splitter objectAtIndex:i]stringByReplacingOccurrencesOfString:@" " withString:@""];
}
else if(i==7)
{
t = [[splitter objectAtIndex:i]stringByReplacingOccurrencesOfString:@" " withString:@""];
}
}