std::string 杂记

std::string strSubtitle =@"";



 



 if( ! strSubtitle.empty() ) //判断字符串的是否为空



    {



        CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 22);



        addChild(l, 1);



        l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 60) );



    }    



string的追加



 



       std::string s1 = "hello";



    std::string s2 = "world";



    std::string s3 = s1 + "," + s2 +"!\n";



 CCLog("%s",s3.c_str());



也可以 sprintf("%d.png", i);搞定



string 比较



 



if (s1=="hello") {



        CCLog("一样");



 }



 



string遍历节点



 



 



 for(int i = 0 ; i < s3.size(); i ++){



        CCLog("%c\n",s3[i]);



    }



 



//



 



 int index = str.find("baidu");//查找字符串字母位置



 str.replace(index, 5, "sain");//把规定字符串替换



  CCLog("%s",str.c_str());



//把char 类型转数组 通过","

    char*gs;



    int a[2];



    std::string testString= "1,2,3";



    char *order;



 



    strcpy(gs, testString.c_str());



    order = strtok (gs,",");



    int i=0;



    while(order!=NULL) {



        CCLog( "%s",order );



        int aa= atoi(order);



        CCLog("%d",aa);



        order = strtok(NULL,",");



        a[i]=aa;



         i++;



    }



    CCLog("%d",a[1]);

 

你可能感兴趣的:(String)