• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

稻草人MNMN

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

限制字符串 剔除费需要字符然后将多余空格删除

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' ' )
            }

 

posted on 2019-08-07 20:44  稻草人MNMN  阅读(182)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3