0

我有:LPWSTR str=" Nguyen Phong Sac " 如何修剪 str。它的意思是:str="Nguyen Phong Sac"

4

1 回答 1

0

尝试这个。请注意,此功能尚未经过彻底测试,只是为了了解一下。

void Trim(TCHAR *buffer)
{
  int i = 0;

  while (buffer[i++] == ' ' && buffer[i] != 0) 
  {
  }

  int first = i - 1 ;

  i = lstrlen(buffer)  ;

  while (buffer[--i] == ' ' && i > 0) 
  {
  }

  int last = i + 1 ;

  int j = 0 ;
  for (i = first; i <= last - first; i++)
    buffer[j++] = buffer[i] ;

  buffer[j] = 0 ;
}
于 2013-03-26T07:41:38.237 回答