for( int i=0; i<strCompletionDataList.GetLength(); i++) { if( !((strCompletionDataList[i]>=L'a' && strCompletionDataList[i]<=L'z')||(strCompletionDataList[i]>=L'A' && strCompletionDataList[i]<=L'Z') ||(strCompletionDataList[i]>=L'0' && strCompletionDataList[i]<=L'9') ||(strCompletionDataList[i]==L' '))) { strCompletionDataList.Replace(strCompletionDataList[i],L' ');//将不合要求字符更替为空格 } if( strCompletionDataList[i] == L' ' ) { spaceCount++; if((i+1)<strCompletionDataList.GetLength())//判断未抵达最后一位 { if( strCompletionDataList[i+1] != L' ' )//下一位不是空格 { if(spaceCount > 1) { strCompletionDataList.Delete(i-(spaceCount-1),spaceCount-1); i-=(spaceCount-1); spaceCount = 0; } else if (spaceCount = 1) spaceCount = 0; } } else if((i+1)>=strCompletionDataList.GetLength())//判断本位就是最后一位 { strCompletionDataList.Delete(i-(spaceCount-1),spaceCount); spaceCount = 0; } }// end if( strCompletionDataList[i] == L' ' ) }