NSString 基本使用

NSString 是 Object C 中常用的类,在处理字符串时提供了很多的方法,就像java中的String一样,下面我列举了平时会使用的到一些方法,欢迎补充。

在Object中用‘@’来代码NSString的数据类型。

初始化

NSString *t = @"nsstringtest"

NSString   *queryStr  = [ NSString stringWithFormat:@"select  patient.Birthday,\
                             personal_information.Name,\
                             personal_information.Gender,\
                             personal_information.Phone_Mobile,\
                             personal_information.Phone_Home,\
                             personal_information.Phone_Work,\
                             personal_information.Email,\
                             personal_information.Address \
                             from personal_information join patient on patient.PHR_ID=personal_information.PHR_ID  \
                             where personal_information.PHR_ID=(select PHR_ID from phr_entry where PHR_ID=1)",1];

连接

将几个NSString字符串进行连接

NSString* str1; NSString* str2

1. NString* str3= [NSString initWithFormat:@"%@,%@", str1, str1];

2. NString* str3= [string1 stringByAppendingString:str2];

3 . NString* str3= [string stringByAppendingFormat:@“%@,%@”,str1, str2];

其中 format 的格式为:

‘%@’   是格式化 NSString 类型

%d, %D, %i 是格式化  32位有符号整数 (int)

转换

int 到 NSString:   [NSString stringWithFormat:@"%d", myInt];

NSString 转int,float 都是类型的

int myInt = [str1 intValue]

送上Cocoa China上一段获取系统当前时间的代码,

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM-dd-hh-mm-ss"];
    NSString*locationString=[formatter stringFromDate: [NSDate date]];
    NSArray*timeArray=[locationString componentsSeparatedByString:@"-"];
    float value_D=   [[timeArray objectAtIndex:1]floatValue];
    float value_h=  [ [timeArray objectAtIndex:2]floatValue];
    float value_m= [ [timeArray objectAtIndex:3]floatValue];
    float value_s=  [ [timeArray objectAtIndex:4]floatValue];
    float value_All=value_D*24*60*60+value_h*60*60+value_m*60+value_s;
    [formatter release];

无觅相关文章插件,快速提升流量

Leave a comment

2 Comments.


发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Bad Behavior has blocked 1475 access attempts in the last 7 days.

site tracking with Asynchronous Google Analytics plugin for Multisite by WordPress Expert at Web Design Jakarta.

serial corel draw 11

serial corel draw 11 serials

free corel photoshop download

free corel photoshop download keygen

adobe free

adobe free

key office 2010

office 2010 key

download photo shop free

photo shop serial

free winrar download for xp

download winrar for xp for free

windows 7 free

windows 7 crack

cs5 serialz

cs5 serialz free

free corel downloads

free corel downloads cracked

office 2010 free

office 2010 key

winrar password cracker serial

wirar password cracker

serial winzip 11

serial winzip 11 key

photoshop key

photoshop key

windows key

windows key

corel dvd moviefactory 6

corel dvd moviefactory 6 downloads

office 2010 professional key

office 2010 key

photo shop key

photo shop key

winrar 3 download

winrar 3 download freedownload

windows 7 key

windows 7 key