【ios 汇总 - 数据 容器】

dictionary

 遍历字典

NSLog(@"***遍历字典myClassDict如下:");
for (id key in myClassDict)
{
NSLog(@"key: %@ ,value: %@",key,[myClassDict objectForKey:key]);
}


[_surveyAnswers1 setObject:myArrayAnswers1 forKey:@"FirstKey"];


for (NSString *key in [cacheDict allKeys]) {}


array 

快速创建array 

//NSMutableArray *array = [NSMutableArray arrayWithObjects:   @"One",@"Two",@"Three",nil]; 


[ _list  addObjectsFromArray:[indexlist copy]];

_filteredList   = [ _stringList  filteredArrayUsingPredicate:[NSPredicatepredicateWithFormat:@"SELF contains[cd] %@", searchString]];

从plist 导入array

NSString   *path = [[ NSBundle mainBundlepathForResource:@"CmdStrList"ofType:@"plist"];
        _cmdlist = [[NSArrayallocinitWithContentsOfFile:path];

/*-------------数组枚举---------------*/      
//- (NSEnumerator *)objectEnumerator;从前向后  
//NSMutableArray *array = [NSMutableArray arrayWithObjects:  
@"One",@"Two",@"Three",nil];  
NSEnumerator *enumerator;  
enumerator = [array objectEnumerator];  
  
id thingie;  
while (thingie = [enumerator nextObject]) {  
    NSLog(@"thingie:%@",thingie);  
}  
  
//- (NSEnumerator *)reverseObjectEnumerator;从后向前  
//NSMutableArray *array = [NSMutableArray arrayWithObjects:  
@"One",@"Two",@"Three",nil];  
NSEnumerator *enumerator;  
enumerator = [array reverseObjectEnumerator];  
  
id object;  
while (object = [enumerator nextObject]) {  
    NSLog(@"object:%@",object);  
}  


  NSString

1)componentsSeparatedByString:截取指定字符串;

2) pathForResource:获取程序运行时目录

3)  objectAtIndex:获取当前索引的字符串;

4)  rangeOfString:获取指定短字符串在长字符串中的开始,结尾索引值;

5) stringWithContentsOfFile:按行读取文件

6) componentsSeparatedByString:@"\n"];换行分割字符串;

7) NSEnumerator *nse = [lines objectEnumerator]; 将数组转换为NSEnumerator,可向前读取数据;

8)  nextObject:读取下一行数据;

 

void splitString(){

NSString *animals = @"dog#cat#pig";

//#分隔的字符串转换成数组

NSArray *array = [animals componentsSeparatedByString:@"#"];

NSLog(@"animals:%@",array);

//获取程序运行时目录

NSString *escapedPath = [[NSBundle mainBundlepathForResource:@"info" ofType:@"plist"];

NSArray *strings = [escapedPath componentsSeparatedByString@"/"];

NSString *tmpFilename  = [strings objectAtIndex:[strings count]-1];

NSRange iStart = [escapedPath rangeOfString : tmpFilename];

NSString *runtimeDirectory = [escapedPath substringToIndex:iStart.location-1];

NSLog(@"runtimeDirectory:%@",runtimeDirectory);

//按行读取文件

NSString *tmp;

NSArray *lines = [[NSString stringWithContentsOfFile:@"test.txt" encoding:nil error:nil

  componentsSeparatedByString:@"\n"];

NSEnumerator *nse = [lines objectEnumerator];

while(tmp = [nse nextObject]) {

NSLog(@"tmp:%@", tmp);

}

}

 
rang.location 指向的是 @"//" 的头一个字符
     NSRange   range;
    range = [url
  rangeOfString : @"//" ];
   
  if   (range. length   >   0 ) {
        url = [url
  substringFromIndex :range. location   + range. length ];
    }

从 // 之后截取
    range = [url  rangeOfString : @"/" ];
   
  if  (range. length  >  0 ) {
        url = [url
  substringFromIndex :range. location  +  1 ];
    }

截取到 # ,不包含#
    range = [url
  rangeOfString : @"#" ];
   
  if  (range. length  >  0  && range. location  >  0 ) {
        url = [url
  substringToIndex :range. location ];
    }


modulename = [ NSString stringWithUTF8String:(*itStr).c_str()];
NSString * welcomeInfo =[ @" 欢迎回来  " stringByAppendingString:nickName];
NSString  *servantCmd = [ NSString  stringWithFormat:@"wnsxms.%@",@"getcommandlist"];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值