zoukankan      html  css  js  c++  java
  • 错误C2137:c中的字符常量为空++

    代码如下:

    void SomeClass::SomeFunctionToCorrectName(CString &strName)
    {
            
        //  Only alphabets (Aa-Zz), numbers(0-9), "_" (underscore) and "-" (hyphen) are allowed. 
                    
            for(int nIndex = 0; nIndex < strName.GetLength(); nIndex++)
            {
                TCHAR currentChar = strName.GetAt(nIndex);
                
                if((currentChar >= _T('a') && currentChar <= _T('z')) ||
                    (currentChar >= _T('A') && currentChar <= _T('Z')) ||
                    (currentChar >= _T('0') && currentChar <= _T('9')) ||
                    currentChar == _T('-') || currentChar == _T('_'))
                {
                    continue;
                }
                strName.Replace(currentChar,_T(''));    
            }
    }
    

    此方法删除strName中的任何额外内容,并且只允许使用(Aa-Zz)、numbers(0-9)、{(下划线)和“-”(连字符)。国际单项体育联合会要检查那些允许的条件。如果它不在允许的条件下,它将删除它。

    For Eg desired i/p :"Hel*lo*World" and desired o/p : "HelloWorld"
    

    但下面给出的错误如下:

    error C2137: empty character constant
    
    I can fix this error by using any of the three methods:
    1. using ''
    2. using ' ' (space in between ' ')
    3. using ""[0]
    

    但这会在更换时引入空间。

    Input :Hel*lo*World
    Output :Hel lo World
    Desired Output :HelloWorld
    

    有人能告诉我怎样才能得到想要的结果吗?

    如果要删除特定字符,则Replace不是正确的方法。正如您所注意到的,没有任何合理的方法可以代替这个角色。

    相反,您可以像这样使用Remove

    strName.Remove(currentChar);

    refer to:https://www.5axxw.com/questions/content/ksso5b
  • 相关阅读:
    java8 Stream排序字段为空排序方法
    SpringBoot使用token简单鉴权的具体实现方法
    性能调优
    TestNG最简单的测试
    TestNG异常测试
    TestNG中如何执行测试
    TestNG的基本注解
    TestNG介绍
    TestNG 环境搭建
    python第四课笔记
  • 原文地址:https://www.cnblogs.com/tewuapple/p/14892161.html
Copyright © 2011-2022 走看看