Search code examples
c++cocos2d-x

String with CCArray


I want to store the string in array values with specified position.

For example:

The letter "A" is stored in 3rd position in an array(CCArray). No values in other position.

I am trying the following code

 world->insertObject(character,2);    //character is CCString

The above method is pushed the existing values to next place. I want to over write the existing one.

The new character is stored in second place. There is no need old value.

Can any one assist me?


Solution

  • The above logic have the following coding

    word->removeObjectAtIndex(4);
    word->insertObject(character,4);
    

    First remove the string and then insert the CCString.

    Now it works fine.