//字符串长度
int calcCharCount(constchar *pszText)
{
int n =0;
char ch =0;
while ((ch = *pszText))
{
CC_BREAK_IF(! ch);
if ((0x80 & ch) ==0x00) {
n++;
}elseif (0x80 != (0xC0 & ch)) {
n+=2;
}
++pszText;
}
return n;
}
//包含特殊字符
bool checkSpecialCharacter(string text)
{
char temp;
for (int i =0; i <text.length(); i++) {
temp = text[i];
if ((temp >=0 && temp <=47) || (temp >=58 && temp<=64) || (temp >=91 && temp <=96) || (temp >=123 && temp <=127 )) {
CCLog("用户名称包含特殊字符");
returntrue;
}
}
return false;
}
//数字转换为欧洲千位分隔符,逗号分隔符,实现10亿,1.09,2.2
constchar* getNumberByEurope(longlong number)
{
//第二种,使用c++
//char temp2[50];
//sprintf(temp2, "%lld",number);
//string numberString = temp2;
//第一种在cocos2d-x平台下使用
CCString *temp =CCString::createWithFormat("%lld",number);
string numberString = temp->getCString();
int length = numberString.length();
int move =3;//每三位分割
while (length >0 && length - move >0) {
numberString.insert(length - move,",");
length -= move;
}
CCLog("numberString : %s",numberString.c_str());
return numberString.c_str();
}
constchar* getNumberByShort(longlong money)
{
string s;
CCString *temp;
if (money >=10000 && money <100000000) {
money /=10000;
s = Logic::getStringRes(UICommon_num1);
temp =CCString::createWithFormat("%lld%s",money,s.c_str());
}elseif (money >=100000000){
double number = (double)money;
//number = 123456789;
number /=100000000;
s = Logic::getStringRes(UICommon_num2);
temp =CCString::createWithFormat("%.2f%s",number,s.c_str());
string str = temp->getCString();
string::iterator it;
bool flag =false;
for (it = str.begin(); it != str.end(); it++) {
CCLog("--%c--",*it);
if (*it =='.') {
it++;
if (*it =='0') {
if (*it =='0' && *(it+1) =='0') {
str.erase(it);
str.erase(it);
it--;
str.erase(it);
}
break;
}else{
it++;
if (*it =='0') {
str.erase(it);
}
break;
}
}
}
CCLog("str: %s",str.c_str());
temp =CCString::create(str.c_str());
}else{
money = money;
s ="";
temp =CCString::createWithFormat("%lld%s",money,s.c_str());
}
CCLog("temp: %s",temp->getCString());
return temp->getCString();
}
string UtilManager::replace(string res, string a, string b) {
while (res.find(a) != string::npos)
res.replace(res.find(a), a.length(), b);
return res.c_str();
}