一:utilstring.h
#pragma once
#include
#include
namespace utilstring
二:utilstring.cpp
#include "stdafx.h"
#include "utilstring.h"
#include
#include
using namespace std;
//namespace utilstring
retstr = pwstr;
free(pwstr);
return retstr;
}std::string convertwidechartomultibyte(const std::wstring& wstrsrc) //wstring to string
ret = pstr;
free(pstr);
return ret;
}wstring convertmultibytetowidecharutf8(const std::string& strsrc)
pwstr[len-1] = 0;//added by kevin, 2008/08/19, in order to set pwstr to null terminated string
wstrret = pwstr;
return wstrret;
}//must free lpwstr after call this func
string convertwidechartomultibyteutf8(const std::wstring& wstrsrc)
strret = pstr;
return strret;
}// the strdes must be the char array
void widetomultibyte(std::wstring &strsrc, char* strdes)
//make lower
string stringmakelower(const string& strsrc)
wstring stringmakelower(const wstring& strsrc)
//convert to low string. then search str in str
bool findstringinstring(const wstring& strsrc0, const wstring& strtofind0)
//str to d
uint convertstringtonumber(const wstring& wstr)
const string str0= convertwidechartomultibyte(wstr );
int num = atoi( str0.c_str() );
return num;
}//sscanf("a0", "%02x", &num1);
//get number from string like "0x84acef"
uint converthexstringtonumber(const std::wstring& wstrold)
else if(pos >15)
else
}return num;
}//字串中有一段連著的數字
int getnumberfromstring(const wstring& str)
else
posend = idx;
}else if(posstart >= 0)
else{}
}if(posstart < 0)
//assert(posend - posstart + 1 >= 0 );
if(posend - posstart + 1 < 0) return 0;
wstring wstrsub = str.substr(posstart, posend - posstart + 1);
string strsub = utilstring::convertwidechartomultibyte(wstrsub);
numberret = atoi(strsub.c_str() );
return numberret;
}std::wstring numbertowstring(int number)
//判斷是否乙個string全部是數字, 如有, 轉換
bool checkstringisnumber(const std::wstring& wstrold, int& number)
}if(ifnumber)
return ifnumber;}//
void splitstringbychar(cstring allstr, tchar x, std::vector&strarray)
strarray.push_back((lpctstr)allstr.left(aa));//add element//
int bb=allstr.find(x, aa+1);
if(bb==-1)
while(bb!=-1)
strarray.push_back((lpctstr)allstr.mid(aa+1));//add element//
}void splitstring(const std::string& strsource, const char* sep, vector& resultlist)
free(strcopy);
}void splitstring(const std::string& source, const char* sep, vector& resultlist)
free(strcopy);}//
}; //namespace
C 字串轉換篇
printf c 2fn c 執行 c 98.23 atoi 將字串轉換成整型數 相關函式 atof,atol,atrtod,strtol,strtoul 表頭檔案 include 定義函式 int atoi const char nptr 函式說明 atoi 會掃瞄引數nptr字串,跳過前面的空格...
C 各種字串轉換
1 string json 字串轉換為list模型 string字串,轉換為list模型 public listjsonstringtolist string jsonstr 2 json字串轉為實體類 實體類轉為json字串 model model jsonconvert.deserializeo...
字串轉換
我們將僅由若干個同一小寫字母構成的字串稱之為簡單串,例如 aaaa 是乙個簡單串,而 abcd 則不是簡單串。現在給你乙個僅由小寫字母組成的字串,你需要用最小的花費,將其轉換成乙個簡單串。花費的計算規則如下 將a到z這26個小寫字母從左到右排成一排,則每個字母都有左右兩個鄰居,我們認為a的左鄰居是z...