將C++的標識符轉成OC的標識符

來源:互聯網
上載者:User

標籤:data   nic   tin   end   rom   c++   擷取   char   否則   

3.將C++的標識符轉成OC的標識符 C++的標識符和OC一樣由數字字母底線組成。打頭的不是數字。當標識符超過一個單詞, C++採用全字母小寫。單詞間用底線串連的書寫規範,如: bei_jing OC採用除第一個單詞外,其餘單字首大寫的書寫規範。如:beiJing  //傳入C++標識符,返回OC標識符  */+ (NSString *)objcIdentifierFromCppIdentifier:(NSString *)idf//{//    //首先擷取第0個字母//    NSMutableString * str1 = [NSMutableString stringWithFormat:@"%c",[idf characterAtIndex:0]];//    // 從第一個字母往後遍曆。遇到‘_’符號後,取出‘_’後的字元將小寫轉換為大寫,讓i+1。否則,直接拼接//    for (NSInteger i = 1; i < idf.length; i++) {//        unichar ch = [idf characterAtIndex:i];//        if (ch == ‘_‘) {//            ch = [idf characterAtIndex:i+1];//            [str1 appendFormat:@"%c",ch-32];//            i++;//        } else {//            [str1 appendFormat:@"%c",ch];//        }//    }//    return str1;//}//{//    NSMutableString * str = [[NSMutableString alloc]init];//    for (NSInteger i = 0; i < idf.length; i++) {//        unichar ch = [idf characterAtIndex:i];//        if (ch == ‘_‘) {//            unichar ch = [idf characterAtIndex:i+1];//            [str appendFormat:@"%c",ch-32];//            i++;//        }//        else//        {//            [str appendFormat:@"%c",ch];//        }//    }//    return  str;//}{    NSMutableString * str = [ NSMutableString stringWithFormat:@"%c",[idf characterAtIndex:0]];                      for(NSInteger i = 1;i < idf.length;i++)                      {                          unichar ch = [idf characterAtIndex:i];                          if(ch == ‘_‘)                          {                              unichar ch = [idf characterAtIndex:i+1];                              [str appendFormat:@"%c",ch-32];                              i++;                          }                          else                          {                              [str appendFormat:@"%c",ch];                          }                      }    return str;}

將C++的標識符轉成OC的標識符

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.