CString截取
来源:互联网 发布:网络推广培训机构 编辑:程序博客网 时间:2024/05/10 06:38
转载了一些例子。加上自己遇到的例子,目的是熟悉CString的操作
一,文件xxxx.dll去掉后面的.dll
方法1、
char str[] = "xxxx.dll"char*p;p=strrchr(str, '.');*p = 0;
方法2、
CString str="xxxx.dll";int n = str.ReverseFind('.')str = str.Left(str.GetLength()-n-1);
例程2:(csdn)
取得一个字符串中第一个 '?'号之前的字符
方法1
CString m_char,m_disp;m_disp="jadfueiuajdf?";m_char="?";if (!m_char.IsEmpty()) { int index = m_disp.Find(m_char); m_disp = m_disp.Right(m_disp.GetLength()-index-1); }
返回m_disp就行
方法2
CString temp=the.m_bb;CString reslut=temp.Left(temp.Find("?")-1);
例程3:(csdn)
一个CString类对象m_StrReceiveModem={ATS0=2OK$03#}
如何截取从$开始的字符串
方法1
CString m_StrReceiveModem; int nPos = m_StrReceiveModem.Find('$'); if(nPos >= 0) { CString sSubStr = m_StrReceiveModem.Mid(nPos);//包含$,不想包含时nPos+1 }
方法2
CString m_StrReceiveModem; int nPos = m_StrReceiveModem.Find('$'); if(nPos >= 0) { CString sSubStr = m_StrReceiveModem.Right(StrReceiveModem.GetLength()-nPos); }
以及Mid(int nFirst,int nSize)
例程四
定义CString 要找到的一个串截取这个串怎么办???
CString = "abcde base64 baaaaa"
要把base64后面的字符串保留.怎么处理????
现在你给出的字符串已经知道了长度,而且也知道分隔位置在哪儿,直接可以用CString::Right()函数获取后半截,如下:
CString str="abcde base64 baaaaa";
str=str.Right(6);//等式右边得到str的后6个字符组成的字符串然后赋值给str
如果先前不知道分割点的确切位置的话,可以用如下函数查找:
CString::Find() //1
CString::FindOneOf() //2
函数1有如下几个原型:
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR lpszSub, int nStart ) const;
函数2的原型为:
int FindOneOf( LPCTSTR lpszCharSet ) const;
找到分隔点位置后就可以截取了。
与CString::Right(int n)相对的还有CString::Left(int n),它是用来截取字符串前面n个字符的CString str="abcde base64 baaaaa";
CString findstr="base64";
CString mystr;
int k=str.Find(findstr)+findstr.GetLength();
mystr= str.Right(str.GetLength()- k);CString cs;
返回左边的值,cs.left(int x) x为几位;
返回右边的值,cs.right(int x) x为几位;
cs.GetLength();;
我觉得有上面的3个函数,你会使用的话,CString 里面的任意 字符段 都截出来了
AfxMessageBox(mystr);例程五 一个字符串,每遇到换行就保存之前的字符串,并放入数组中。比如CString strLog=_T("lin1\r\nline2\r\nline3\r\nline4\r\n");存放数组list<CString> lstStr,lstStr中内容为 line1,line2,line3,line4.CString strLog = _T("lin1\r\nline2\r\nline3\r\nline4\r\n");list<CString> lstStrout;CString strInfo = "\r\n";CString strTemp = strLog;int index = 0;if ( !strTemp.IsEmpty() && (strTemp.Find(strInfo) >= 0) ){while( 1 ){index = strTemp.Find(strInfo);CString strOut = strTemp.Left(index);lstStrout.push_back(strOut);if ( ( index + strInfo.GetLength() ) == strTemp.GetLength()){break;}strTemp = strTemp.Right(strTemp.GetLength() - index - 2);}}
- CString 截取
- CString 截取
- CString截取
- CString 截取字符串
- cstring 截取字符串
- cstring 截取字符串
- CString截取字串方法
- CString字符串截取
- CString 字符串截取
- CString截取字串方法
- Cstring截取字段
- CString截取字串方法
- CString字符串截取
- CString的截取
- CString截取字符串
- CString截取字串方法
- CString 截取字符串全攻略
- CString截取字符串全攻略
- label j;goto j;
- 关于获得MFC窗口其它类指针的方法
- 如何将uboot里面的参数传给recovery或kernel
- asp.net导航控件
- 让linux定时执行秒级任务
- CString截取
- 为什么越来越多的用户放弃了Linux?
- [How To]在Linux下设置无线网络桥接
- struts2 (一) web.xml/struts.xml/Action 配置
- 一个程序员的哲学思考(关于编程、关于人生)
- write readln(tempStr); writeln(tempStr,'---!');
- 基于单文档的记事本开发 .
- mount nfs ubuntu10.04
- 编程技巧整理