zoukankan      html  css  js  c++  java
  • NSString 与 C++ string字符串的互转

      1.C++ string 转换为 NSString  
    
       std::string str("hello");
        // NSString *str = [NSString stringWithString:str.c_str()];
          NSString *ocstr = [NSStringstringWithCString:str.c_str() encoding:NSUTF8StringEncoding];
    
    
       NSString *istr = [NSString stringWithString:@"zsh"];
        str = [istr cStringUsingEncoding:NSUTF8StringEncoding];
    
     2. NSString 转换为C 字符串
    
        const char* destDir = [filepath UTF8String];
       //  NSURL *soundUrl=[[NSURL alloc] initFileURLWithPath:s]; 
    
    
    3. const char* to NSString
    
       char *str ="abc";
       NSString *s = [NSString stringWithUTF8String:str];
    
       NSString *path = [[NSBundle mainBundle]pathForResource:@"nokia" ofType:@"mp3"];
        char *tempPath = (char*)malloc(sizeof(path)+1);
      
        NSString *soundPath = [[NSBundle mainBundle] pathForResource:@mp3"]; 
        
        NSString *dirStr = [NSString stringWithFormat:@"%s",path];
        NSString *filepath = [[NSBundle mainBundle] pathForResource:dirStr ofType:nil];
        NSLog(filepath);
    

      

  • 相关阅读:
    scott登录查询常用语句
    Oracle服务端及客户端安装
    SVN简单使用
    dos命令--查询进程
    第二周学习总结
    第一周学习总结
    虚拟机安装教程及网络连接方式的解释
    两天学习总结
    方差
    thinkphp 总结 转
  • 原文地址:https://www.cnblogs.com/tomblogblog/p/3719254.html
Copyright © 2011-2022 走看看