字符串NDS_trim.h
来源:互联网 发布:new balance淘宝店 编辑:程序博客网 时间:2024/06/10 23:32
#ifndef _NDS_TRIM_H
#define _NDS_TRIM_H
#include <string>
#include <algorithm>
#include <functional>
#include <cctype>
using namespace std;
namespace NDS
{
inline string& ltrim(string &ss, int (*pf)(int)=isspace)
{
string::iterator p=find_if(ss.begin(),ss.end(),not1(ptr_fun(pf)));
ss.erase(ss.begin(),p);
return ss;
}
inline string& rtrim(string &ss, int (*pf)(int)=isspace)
{
string::reverse_iterator p=find_if(ss.rbegin(),ss.rend(),not1(ptr_fun(pf)));
ss.erase(p.base(),ss.end());
return ss;
}
inline string& trim(string &st)
{
ltrim(rtrim(st));
return st;
}
inline void stringupper(string& str)
{
for (string::iterator i=str.begin();i!=str.end();i++)
*i=toupper(*i);
}
inline void stringlower(string& str)
{
for (string::iterator i=str.begin();i!=str.end();i++)
*i=tolower(*i);
}
template <typename T> inline const string to_string(const T& v)
{
ostringstream os;
os<<v;
return os.str();
}
template <typename T> inline const T from_string(const string& v)
{
istringstream is(v);
T t;
is>>t;
return t;
}
template <typename T> inline void from_string(T& t, const string& v)
{
istringstream is(v);
is>>t;
}
}
#endif
对字符串string去头尾空白字符的操作,新增加了字符串转换成T类型的操作函数。
有一点尚未解决,是任意类型转成字符串时的格式化问题。
- 字符串NDS_trim.h
- 字符串操作之string.h
- time.h获取时间字符串
- 字符串处理函数string.h和wchar.h
- 字符串处理函数string.h和wchar.h(续1)
- 字符串处理函数string.h和wchar.h(续2)
- 字符串专题:H - Blue Jeans(暴力法)
- C/C++<string.h>字符串函数
- C++库函数---<string.h>字符串处理函数
- eclipse查询字符串(ctrl+h)
- 字符串练习题:H - Another String Game
- 字符串处理函数(string.h)
- StrSafe.h 使用安全字符串操作函数
- string.h中常用字符串操作函数
- 字符串处理函数(string.h)
- c语言字符串库函数#include<string.h>
- h
- h
- About me!
- sas9的IT技术
- 请问那里可以下载xp ddk,网上搜索到的都没有办法下载,谢谢!
- 欢迎大家的光临!
- 面向对象的思维方法
- 字符串NDS_trim.h
- 第一次用web blog,不过有点疑问
- Xray@NET,业余写的SNIFFER
- 测试是否正确开通
- 通过JAVA读取串口值(原创)
- 试一下
- Keeping Software Soft 让软件软下去
- 忆今晨春梦,看今朝上班 2004年6月23日
- 牢骚太盛防肠断!