标签:
//第1题 请判断images中存储的图片格式(例如,第X个为png图片)
NSArray *images = @[@"A4E6E10BC0752623.png",@"2DE2C314665048CC.jpg",@"068E12268478787.gif",@"30A030B7C6.jpg"];
for (int i = 0 ; i < [images count]; i++) {
NSString *str = images[i];
NSArray *str3=[str componentsSeparatedByString:@"."];
NSLog(@"第%d照片为%@",i+1,str3[1]);
// if([str hasSuffix:@".png"]){
// NSLog(@"第%d个为png图片",i+1);
// }
// if([str hasSuffix:@".jpg"]){
// NSLog(@"第%d个为jpg图片",i+1);
// }
// if([str hasSuffix:@".gif"]){
// NSLog(@"第%d个为gif图片",i+1);
// }
}
NSString *str0;
NSString *str1;
NSRange range;
NSString *str=[NSString stringWithFormat:@"."];
for(int i=0;i<[images count];i++){
str0=[images objectAtIndex:i];
range=[str0 rangeOfString:str];
str1=[str0 substringFromIndex:range.location];
NSLog(@"第%d个为%@图片",i+1,str1);
}
//第2题 将数组data中的图片遍历出来,存到imageArray(类型为 NSArray)中
NSArray *data = @[CreatDict(1,@"2016-02-02 16:31:10",@"http://112.64.173.178/image/upload/images/goods/2016/2/23/2DE2C314665048CCA4E6E10BC0752623.png",@"123",@"http://www.baidu.com/"),
CreatDict(2,@"2016-02-02 16:31:28",@"http://112.64.173.178/image/upload/images/goods/2016/2/23/9B94AB96D1654A30A030B7C631E623CE.png",@"222",@"http://www.jd.com/"),
CreatDict(3,@"2016-02-02 16:31:49",@"http://112.64.173.178/image/upload/images/goods/2016/2/23/544068E12268478787626F5D2007542B.png",@"333",@"https://www.baidu.com/")];
NSLog(@"将数组data中的图片遍历出来,存到imageArray(类型为 NSArray)中");
NSMutableArray *arr=[[NSMutableArray alloc]init];
for(id a in data){
NSArray *picture=[a[keyImage] componentsSeparatedByString:@"/"];
[arr addObject:[picture lastObject]];
}
NSArray *imageArray=[NSArray arrayWithArray:arr];
for(id b in imageArray){
NSLog(@"%@",b);
}
// NSString *str=@"http://localhost:8099/test/user=admin&password=123456";
// 截取出用户名和密码,但是不是通过位置直接进行截取
NSString *str=@"http://localhost:8099/testone/user=admin&password=123456";
//从某一个字符串得到位置
NSRange ranges=[str rangeOfString:@"user="];
if (ranges.location==NSNotFound) {
NSLog(@"没找到");
}else{
//nsstringFromRange打印一下所求范围
NSLog(@"%@",NSStringFromRange(ranges));
}
NSLog(@"%ld",ranges.length);
NSLog(@"%ld",ranges.location);
NSRange rangeb=[str rangeOfString:@"&password="];
if (rangeb.location==NSNotFound) {
NSLog(@"没找到");
}else{
NSLog(@"%@",NSStringFromRange(rangeb));
}
NSLog(@"%ld",rangeb.length);
NSLog(@"%ld",rangeb.location);
NSString *str1 = [str substringWithRange:NSMakeRange(ranges.length+ranges.location,rangeb.location-ranges.location-ranges.length)];
NSLog(@"该用户的用户名:%@",str1)
long len=[str length];
NSString *str2 = [str substringWithRange:NSMakeRange(rangeb.location+rangeb.length,len-rangeb.length-rangeb.location)];
NSLog(@"该用户密码:%@",str2);
NSArray *str3=[str componentsSeparatedByString:@"="];
NSLog(@"密码为%@",str3[2]);
//减法
int i = 158;
int j = 39;
NSString *str5 = [NSString stringWithFormat:@"%d",i];
NSString *str6 = [NSString stringWithFormat:@"%d",j];
int a =[str5 intValue];
int b =[str6 intValue];
NSLog(@"%d",a-b);
//身份证号
char *str3[100];
NSLog(@"请输入你的身份证号:");
scanf("%s",str3);
NSString *str1=[NSString stringWithUTF8String:str3];
NSString *str1=@"210281199204301251";
long len=[str1 length];
if (len==18) {
NSString *str2 = [str1 substringWithRange:NSMakeRange(16, 1)];
NSRange range;
range.location=6;
range.length=4;
NSString *newStrRange = [str1 substringWithRange:range];
NSRange range2;
range2.location=10;
range2.length=2;
NSString *newStrRange2 = [str1 substringWithRange:range2];
NSRange range3;
range3.location=12;
range3.length=2;
NSString *newStrRange3 = [str1 substringWithRange:range3];
int e = [str2 intValue];
if(e%2==0){
NSLog(@"该用户生日是:%@年%@月%@日",newStrRange,newStrRange2,newStrRange3);
NSLog(@"该用户的性别是:女");
}
else {
NSLog(@"该用户生日是:%@年%@月%@日",newStrRange,newStrRange2,newStrRange3);
NSLog(@"该用户的性别是:男");
}
/**
* 第1题 请将你的身份证号的出生日期部分用*代替,并输出(例如:210304******2248)
* PS:要求除打印外,代码行数最多为3行,
*/
NSMutableString *str=[NSMutableString stringWithFormat:@"210103199407062110"];
[str replaceCharactersInRange:NSMakeRange(6, 8) withString:@"********"];
NSLog(@"%@",str);
//将2013年05月05日转换为2013-05-05
NSString *arr=@"2013年05月05日";
NSString *arr1=[arr stringByReplacingOccurrencesOfString:@"年" withString:@"-"];
NSString *arr2=[arr1 stringByReplacingOccurrencesOfString:@"月" withString:@"-"];
NSMutableString *arr3=[NSMutableString stringWithString:arr2];
NSString *arr4 = [arr3 stringByReplacingOccurrencesOfString:@"日" withString:@""];
NSLog(@"%@",arr4);
}
//1.对字符串“2015-09-01 08:19:10”操作,输出"08:19:10"。要求使用两种截取方式。
NSString *str=@"2015-09-01 08:19:10";
NSString *str1=[str substringFromIndex:10];
NSLog(@"%@",str1);
NSRange range;
range.length=9;
range.location=10;
NSString *str2=[str substringWithRange:range];
NSLog(@"%@",str2);
NSArray *str3=[str componentsSeparatedByString:@" "];
NSLog(@"%@",str3[1]);
//1.以下是身份证号,输出身份证人的性别,年龄
NSLog(@"第一题");
NSString *idCard=@"210423198809040427";
//身份证倒数#2位是偶数则为女生
NSRange range1;
NSRange range2;
range1.length=1;
range1.location=16;
range2.length=4;
range2.location=6;
NSString *newid1=[idCard substringWithRange:range1];
NSString *newid2=[idCard substringWithRange:range2];
int num1=[newid1 intValue];
int num2=[newid2 intValue];
int age=2016-num2;
if (num1%2==0) {
NSLog(@"性别:女 年龄:%d",age);
}else{
NSLog(@"性别:男 年龄:%d",age);
}
标签:
原文地址:http://www.cnblogs.com/houyigood/p/5443178.html