zoukankan      html  css  js  c++  java
  • OC学习将C语言字符串转换为OC字符串

    • 将C语言字符串转换为OC字符串
     1 /**
     2  *  inputNSString:自定义函数
     3  */
     4 #import <Foundation/Foundation.h>
     5 /**
     6  *  将C语言字符串转换为OC语言字符串
     7  *  @return OC语言字符串
     8  */
     9 NSString *inputNSString(){
    10     char arr[256];//假定数组长度为256
    11     char ch;
    12     int length=0;
    13     //while ((ch=getchar())!='
    '){//判断获取的字符是否为'
    '
    14     while (scanf("%c",&ch),ch!='
    ') {//利用逗号表达式特性,先接收字符,然后判断是否为'
    '
    15         arr[length++]=ch;//将获取到的字符依次存到str数组中
    16     }
    17     return [[NSString alloc]initWithUTF8String:arr];//讲C字符串转换为OC字符串
    18 }
    19 
    20 int main(int argc, const char * argv[]) {
    21     @autoreleasepool {
    22         NSString *str1=inputNSString();//调用inputNSString函数
    23         NSLog(@"%@",str1);
    24     }
    25     return 0;
    26 }
  • 相关阅读:
    std::string构造函数
    shell命令-while语句
    shell命令-for语句
    shell命令-if语句
    softmax回归推导
    sigmod函数求导
    生成器面试题之一
    range和xrange的区别
    python里的input
    python中print和input的底层实现
  • 原文地址:https://www.cnblogs.com/studyrecord/p/4824038.html
Copyright © 2011-2022 走看看