2013/4/15整理:

将整数转换成字符串 Convert Integer to NSString:
方法一:
int Value = 112233;
NSString *ValueString = [NSString stringWithFormat:@"%d", Value];
方法二:
[[NSNumber numberWithInt: 123] stringValue];
 
得到C风格的字符串 C String
char *ValueasCString = (char *)[ValueString UTF8String];
 
将字符串转换成整数或浮点数
Convert String to Integer or float
NSString has some useful methods:
-(int) intValue
-(float) floatValue
NSString *aNumberString = @"123";
int i = [aNumberString intValue];
 
字符串转换为日期
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];//实例化一个NSDateFormatter对象
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式
NSDate *date =[dateFormat dateFromString:@"1980-01-01 00:00:01"];
 
日期转换为字符串
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];//实例化一个NSDateFormatter对象
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式
NSString *currentDateStr = [dateFormat stringFromDate:[NSDate date]];
使用NSNumberFormatter将数值转换成字符串
Simplifying NSNumberFormatter Use on the iPhone With Objective-C Categories
Here are the different formatter styles, and the result when converting [NSNumber numberWithDouble:123.4] into an NSString.
NSNumberFormatterNoStyle (123)
NSNumberFormatterDecimalStyle (123.4)
NSNumberFormatterCurrencyStyle ($123.40)
NSNumberFormatterPercentStyle (12,340%)
NSNumberFormatterScientificStyle (1.234E2)
NSNumberFormatterSpellOutStyle (one hundred and twenty-three point four)
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterCurrencyStyle;
NSString *string = [formatter stringFromNumber:number];
[formatter release];

Objective-C中整数与字符串的相互转换的更多相关文章

  1. php中数组和字符串的相互转换

    数组转字符串: implode('!', $arr);//将一维数组以!分隔组合成一个字符串,参数一可以为"" 字符串转数组: explode('!', $str);//将字符串以 ...

  2. 【js中数组和字符串的相互转换】

    一.数组转字符串 //数组转字符串 var a, b; a = new Array(0,1,2,3,4); b = a.join(","); //得到字符串 二.字符串转数组 // ...

  3. objective C中的字符串NSStirng常用操作

    objective C中的字符串操作 在OC中创建字符串时,一般不使用C的方法,因为C将字符串作为字符数组,所以在操作时会有很多不方便的地方,在Cocoa中NSString集成的一些方法,可以很方便的 ...

  4. MYSQL中日期与字符串间的相互转换

    一.字符串转日期 下面将讲述如何在MYSQL中把一个字符串转换成日期: 背景:rq字段信息为:20100901 1.无需转换的: SELECT * FROM tairlist_day WHERE rq ...

  5. GO数值和字符串的相互转换

    转自:http://blog.sina.com.cn/s/blog_9e14446a01018m9i.html 在做项目的时候,通常都会碰到字符串转换,在这介绍一下字符串与整型的相互转换.在golan ...

  6. [转]:Delphi中Format的字符串格式化使用说明

    一.Format函数的用法 Format是一个很常用,却又似乎很烦的方法,本人试图对这个方法的帮助进行一些翻译,让它有一个完整的概貌,以供大家查询之用: 首先看它的声明: function Forma ...

  7. JavaScript中,提取子字符串方法:Slice、Substring、Substr的比较。

    在JavaScript中,提取子字符串主要是通过 Slice.Substring.Substr 三个方法之一. // slice // 语法: string.slice(beginSlice [, e ...

  8. js String对象中常用方法小结(字符串操作)

    1.charCodeAt方法返回一个整数,代表指定位置字符的Unicode编码. strObj.charCodeAt(index) 说明: index将被处理字符的从零开始计数的编号.有效值为0到字符 ...

  9. 【循序渐进学Python】3. Python中的序列——字符串

    字符串是零个或多个的字符所组成的序列,字符串是Python内建的6种序列之一,在Python中字符串是不可变的. 1. 格式化字符串 字符串格式化使用字符串格式化操作符即百分号%来实现.在%左侧放置一 ...

随机推荐

  1. [Android] Android 手机下 仿 今日头条 新闻客户端

    利用一个月的时间,自学了 Android 开发 ,为了检验学习成果,特意 开发了这个  仿 今日头条 新闻客户端 AppNews 包括图文新闻+视频新闻+图片新闻 预览演示如下: 功能说明: 1)底部 ...

  2. win10中使用 Windows照片查看器

    新建一个txt,将文件后缀名改为 .reg 用记事本或者其他txt编辑器编辑,复制下面文字: Windows Registry Editor Version 5.00 ; Change Extensi ...

  3. Java IO与网络编程笔记

    <!doctype html>Java IO&NIO figure:first-child { margin-top: -20px; } #write ol, #write ul ...

  4. react 监听页面滚动

    html: // 如果使用typescript, 定义dom类型 private dom: HTMLDivElement | null // ReactJS中,对Div监听只需要绑定 onScroll ...

  5. springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo

    1.使用idea新建项目 2.使用Mybatis-Generator自动生成Dao.Model.Mapping相关文件 3.配置application.yml文件 server: port: 8080 ...

  6. Spring Cloud 之 服务注册与发现

    作为微服务框架,提供服务注册发现是最基本的功能.Spring Cloud 针对服务注册发现 提供了 Eureka版本的实现 .Zookeeper版本的实现.Consul版本的实现.由于历史原因 Eur ...

  7. Oracle建立全文索引详解

    Oracle建立全文索引详解1.全文检索和普通检索的区别 不使用Oracle text功能,当然也有很多方法可以在Oracle数据库中搜索文本,比如INSTR函数和LIKE操作: SELECT *FR ...

  8. 处理H5新标签方法

    语义化 HTML5中加入了更加具有语义化的标签,比如header,nav,footer等,可以为搜索引擎优化,让爬虫能更好地理解网页结构. 但是对于新标签的兼容性不是很好,IE9以下旧版本不支持新的语 ...

  9. Deep face recognition: a survey v4

    http://www.cnblogs.com/shouhuxianjian/p/9789243.html

  10. IntelliJ IDEA设置svn.exe的路径

    安装TortoiseSVN客户端时,必须选中command line client tools这个选项