0

我有一个包含许多颜色代码的字符串对象,例如ci=0,0,0ci=0,25,225我想在两个颜色代码之间取一个子字符串并在该范围内更改颜色。有没有人有一个简单的方法来完成这个任务?

例如:

ci=0,0,0You are at a walkway.  
ci=0,0,0You are facing west. You see the ci=0,32,225creature controller roomci=0,0,0 to the ci=0,32,225northci=0,0,0

每个ci=0,0,0都是不同颜色的标签,应该为紧随其后的字符串显示。

我想删除 ci 颜色代码并只显示文本,但颜色正确。

4

1 回答 1

0

用这个:

NSString *testString= @"0,0,0You are at a walkway";
NSArray *array = [testString componentsSeparatedByString:@","];

你将拥有:

array[0] = "0"
array[1] = "0"
array[2] = "0You are at a walkway"

如果您还在“...0You...”中的“0”和“You”之间添加逗号,则会更容易,因为您将拥有:

array[0] = "0"
array[1] = "0"
array[2] = "0"
array[3] = "You are at a walkway"
于 2013-10-29T06:39:46.143 回答