solove

例程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"

分类:

技术点:

相关文章:

  • 2021-10-03
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
  • 2022-02-03
猜你喜欢
  • 2022-01-20
  • 2021-11-19
  • 2022-02-11
  • 2022-01-25
  • 2022-02-10
  • 2021-12-12
  • 2021-12-29
相关资源
相似解决方案