CCString 类

CCString继承至CCObject,CCObjecte这个基类主要是为了自动内存管理而创建的。CCString提供一系列的接口,例如create,convert等等。

 

常用的方法

 

/**使用std::string创建了一个字符串, 你也可以传递一个c字符串指针,因为std::string的构造函数可以访问c字符串指针
 
* @返回的 CCString 指针是一个自动释放对象,
 
*也就意味着你不需要调用release操作,除非你retain了.
 
*/
 
staticCCString* create(const std::string& str);
 
/**使用格式化方式来创建一个字符串,这个方法和c语言里面的‘sprintf’类似,默认缓存大小是(1024*100)bytes
 
*假如你想要改变这个缓存大小,你可以去CCString.cpp中,更改kMaxStringLen 这个宏定义。
 
 
* @返回的 CCString 指针是一个自动释放对象,
 
*也就意味着你不需要调用release操作,除非你retain了.
 
*/
 
staticCCString* createWithFormat(constchar* format,…);
 
/** 使用二进制数据来创建字符串
 
* @返回的 CCString 指针是一个自动释放对象,
 
*也就意味着你不需要调用release操作,除非你retain了.
 
*/
 
staticCCString* createWithData(constunsignedchar* pData,unsignedlong nLen);
 
/**使用一个文件来创建一个字符串,
 
* @return A CCString pointer which is an autorelease object pointer,
 
* it means that you needn't do a release operation unless you retain it.
 
*/
 
staticCCString* createWithContentsOfFile(constchar* pszFileName);

CCString允许CCString实例变量转换为另外类型的变量。

    /** convert to int value */
 
    int intValue() const;
 
    /** convert to unsigned int value */
 
    unsigned int uintValue() const;
 
    /** convert to float value */
 
    float floatValue() const;
 
    /** convert to double value */
 
    double doubleValue() const;
 
    /** convert to bool value */
 
    bool boolValue() const;
    

 

常用的宏定义

#define CCStringMake(str) CCString::create(str)
 
#define ccs CCStringMake

 

 

转载于:https://www.cnblogs.com/ben-android/p/3401149.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值