C 和 OC 字符串转换 NSString 和 char * 转换 const char* 与 char *
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
char *s = "Hello";
//C - > OC
NSString * str1 = [[NSString alloc] initWithUTF8String:s];
//OC -> C
const char *p1 = [str1 UTF8String];
const char *p2 = [str1 cStringUsingEncoding:NSASCIIStringEncoding];
NSLog(@"%s %s",p1,p2);
// const 声明的字符串不允许改变
return 0;
}
C 和 OC 字符串转换 NSString 和 char * 转换 const char* 与 char *的更多相关文章
- OC第二节 —— NSString和NSMutableString
1.为什么需要NSString对象 答:在OC中创建字符串时,一般不使用C的方法, 因为C将字符串作为字符数组,所以在操作时会有很多不方便的地方, 在Cocoa中NSStri ...
- 字符串处理 - ANSI - Unicode - UTF8 转换
#include <stdio.h> #include <windows.h> #include <locale.h> #define BUFF_SIZE 1024 ...
- OC字符串NSString
========================== 面向对象编程进阶和字符串 ========================== Δ一.类的设计模式—单例 [单例]程序允许过程中,有且仅有一块内存 ...
- C++ 字符串、string、char *、char[]、const char*的转换和区别
1.字符串 字符串本质就是一串字符,在C++中大家想到字符串往往第一反应是std::string(后面简称string) 字符串得从C语言说起,string其实是个类,C语言是没有class的,所以C ...
- [基础-001]C++字符串转换(char*,const char*,string)
1. string转const char* string str ="abc"; const char* charArr = str.c_str(); 2. const char* ...
- oc 字符串
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- OC字符串常用函数
创建一个字符串对象: NSstring * str1 = @"hello"; NSString * str = [[NSString alloc]initWithString:@& ...
- QF——OC字符串
OC中的字符串: C中没有字符串类型,用字符数组和指针代替. OC中引入了字符串类型,它包括NSString 和 NSMutableString两种 NSString是不可变的,已经初始化便不能更改: ...
- OC字符串的使用(一)
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- oc随笔四:NSString、NSNumber
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
随机推荐
- mybatis0207 resultType、resultMap、延迟加载使用场景总结
延迟加载: 延迟加载实现的方法多种多样,在只查询单表就可以满足需求,为了提高数据库查询性能使用延迟加载,再查询关联信息. mybatis提供延迟加载的功能用于service层. resultType: ...
- mysql使用硬链接配合truncate 删除2.2T的表 --杨奇龙
http://blog.csdn.net/wyzxg/article/details/8626814 http://blog.itpub.net/22664653/viewspace-750408/ ...
- linux 内核分析+使用SystemTap调试新增内核模块
http://blog.chinaunix.net/uid/14528823/list/1.html?cid=189394
- Qt 学习之路:坐标系统
在经历过实际操作,以及前面一节中我们见到的那个translate()函数之后,我们可以详细了解下 Qt 的坐标系统了.泛泛而谈坐标系统,有时候会觉得枯燥无味,难以理解,好在现在我们已经有了基础. 坐标 ...
- 每天一句 linux命令
1. :进入系统根目录 命令: cd / 2. cd .. 返回上一级目录 3. 例3:跳转到指定目录 命令: cd /opt/soft
- Web性能优化系列
web性能优化之重要,这里并不打算赘述.本系列课程将带领大家认识.熟悉.深刻体会并且懂得如果去为不同的站点做性能优化 同时,本系列将还会穿插浏览器兼容性相关问题的解决方案,因为在我看来,兼容性同样属于 ...
- ICMP协议
1. ICMP简介: ICMP全名为(INTERNET CONTROL MESSAGE PROTOCOL)网络控制报文协议,协议号为1,网络层协议. 它是TCP/IP协议族的一个子协议,用于在IP主机 ...
- 关于EF查询表里的部分字段
这个在项目中用到了,在网上找了一下才找到,留下来以后自已使用. List<UniversalInfo> list =new List<UniversalInfo>(); lis ...
- Activity的几种启动跳转方式
一.显示调用方法 •Intent intent=new Intent(this,OtherActivity.class); //方法1 •Intent intent2=new Intent(); • ...
- WinForm中的事件触发机制学习
在一个Form窗体中拖个按钮,双击后系统自动生成代码: private void button1_Click(object sender, EventArgs e) { } 同时在窗体的Initial ...