Question

I have a string object that contains numerous color codes such as ci=0,0,0 and ci=0,25,225 I would like to take a substring between two color codes and change the color within that range. Does any one have a simple method to complete this task?

For example:

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

Each ci=0,0,0is the tag of a different color that should be displayed for the string immediately following.

I want to delete the ci color code and just display the text, but with the proper color.

Was it helpful?

Solution

Use this:

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

you'll have:

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

If you also add a comma beween the "0" and the "You" in "...0You...", it will be easier, as you'll have:

array[0] = "0"
array[1] = "0"
array[2] = "0"
array[3] = "You are at a walkway"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top