24,860
社区成员




namespace qp
{
typedef std::string StringA;
typedef std::wstring StringW;
typedef std::vector<StringA> VecStringA;
typedef std::vector<StringW> VecStringW;
#ifdef _UNICODE
typedef StringW String;
typedef VecStringW VecString;
#else
typedef StringA String;
typedef VecStringA VecString;
#endif // _UNICODE
class StringHelper
{
public:
// 替换字符,把from替换成to
static void Replace(StringA& str, char from, char to);
static void Replace(StringW& str, wchar_t from, wchar_t to);
// 替换所有字符串,把from替换成to
static void Replace(StringA& str, const StringA& from, const StringA& to);
static void Replace(StringW& str, const StringW& from, const StringW& to);
// 转化成大写、小写
static void Toupper(StringA& str);
static void Toupper(StringW& str);
static void Tolower(StringA& str);
static void Tolower(StringW& str);
// 去除字符串两端空格
static void Trim(StringA& str);
static void Trim(StringW& str);
// 检查字符串是否以某一字串开始
static bool StartWith(const StringA& str, const StringA& head);
static bool StartWith(const StringW& str, const StringW& head);
// 检查字符串是否以某一字串结束
static bool EndWith(const StringA& str, const StringA& tail);
static bool EndWith(const StringW& str, const StringW& tail);
// 字符串转整型、长整型、浮点型
static int ToInt(const StringA& str);
static int ToInt(const StringW& str);
static long ToLong(const StringA& str);
static long ToLong(const StringW& str);
static double ToDouble(const StringA& str);
static double ToDouble(const StringW& str);
// 反转字符串
static void Reverse(StringA& str);
static void Reverse(StringW& str);
// 将from字符串反转到to
static void Reverse(const StringA& from, StringA& to);
static void Reverse(const StringW& from, StringW& to);
// 分隔字符串
static VecStringA Split(const StringA& src, const StringA& token);
static VecStringW Split(const StringW& src, const StringW& token);
};