日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

CString截取字符串全攻略

發布時間:2025/3/21 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CString截取字符串全攻略 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

CString截取字符串全攻略??

源地址?http://blog.163.com/seraph_leo/blog/static/1689297102010786206361/?fromdm&fromSearch&isFromSearchEngine=yes

例程1:(csdn?


文件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=2 OK $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);?
}?
}

?

?

//截取“$”到“#”的字符串

int first,last;

first= m_StrReceiveModem.Find("$");

last= m_StrReceiveModem.Find("#");

CString sSubStr = m_StrReceiveModem.Mid(first,last);

?

?

例程4: (fox)

?

?//根據路徑解析出文件名

?

?CString m_Filepath = "E:\\fox_work\\vc_experiment\\hello.txt"

?int nPos = m_Filepath.Find('\\');
?CString sSubStr = m_Filepath;
??while (nPos)
??{
???sSubStr = sSubStr.Mid(nPos+1,sSubStr.GetLength()-nPos);??//取'\'右邊字符串
???nPos = sSubStr.Find('\\');???//不包含'\',函數值返回-1?

???????if (nPos==-1)????
?????????{
?????????????nPos = 0;
??????????}
??}

?????????//最后sSubStr = "hello.txt"

?

CString::Find()函數??

2010-11-17 12:05:04|??分類:?MFC?|??標簽:?|字號?訂閱

注:CString::Find函數,如果給定的參數是一個字符串,那么它必須與此字符串中的某一個子字符串完全匹配才能返回相匹配的子字符串第一個字符的索引。

?

CString::Find

作用

  在一個較大的字符串中查找字符或子字符串   int Find( TCHAR ch ) const;   int Find( LPCTSTR lpszSub ) const;   int Find( TCHAR ch, int nStart ) const;   int Find( LPCTSTR lpszSub, int nStart ) const;

返回值

  返回此CString對象中與需要的子字符串或字符匹配的第一個字符的從零開始的索引;如果沒有找到子字符串或字符則返回-1。

參數

  ch 要搜索的單個字符。   lpszSub 要搜索的子字符串。   nStart 字符串中開始搜索的字符的索引,如果是0,則是從頭開始搜索。如果nStart不是0,則位于nStart處的字符不包括在搜索之內。   pstr 指向要搜索的字符串的指針

說明

  此成員函數用來在此字符串中搜索子字符串的第一個匹配的字符。函數的重載可以接收單個字符(類似于運行時函數strchr)和字符串(類似于strstr)。

  //下面演示第一個例子

  // CString::Find( TCHAR ch )   CString s( "abcdef" );   int n = s.Find( 'c' ); // 結果 n = 2   int f = s.Find( "de" ) ; // 結果 f = 3   ASSERT( n == 2 );   ASSERT( f == 3 );   // 下面演示第二個例子   // CString::Find(TCHAR ch,int nStart)   CString str("The stars are aligned");   int n = str.Find('e',5); //結果 n = 12   ASSERT(n == 12)

總結

以上是生活随笔為你收集整理的CString截取字符串全攻略的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。