获取子串

来源:互联网 发布:c语言编程病毒 编辑:程序博客网 时间:2024/06/16 15:11

//2011-03-21

//获取子串根据lp,第一个位置,第二个位置(或者长度也可以)

CString getSubString(LPCTSTR lp, int FirstPos, int SecondPos )
{
 if(lp == NULL || SecondPos < FirstPos)
 {
  return "";
 }

 if(SecondPos < 0 || FirstPos < 0 )
 {
  return "";
 }

 CString strTemp ="";
 

 while(FirstPos < SecondPos)
 {
  strTemp += *(lp+FirstPos++); 
 }

 return strTemp; 
}

struct stu
{
 int id;
 char name[15];
 
};

//2011-03-21

 

 

//2011-03-21

//在一个字符串中,获取相同字符串的第多少的位置s

int getCharPos(LPCTSTR lp, int loop, char ch)
{
 if(loop == 0)
 {
  return -1;
 }
 cout << "asdfdfsadfasd" <<endl;
 int i = 0;
 int pos=0;
 while(lp)
 {
  if(ch == *(lp++))
  {
   i++;
  }

  if(i == loop)
  {
   return pos;
  }
  pos++;
 }
}

//2011-03-21