random_names随机名字生成
// 先从txt文件中获取姓和名数组
- (void)getNames{
NSString *resourcePath1 = [[NSBundle mainBundle] pathForResource:@"FirstName" ofType:@"txt"];
NSString *resourcePath2 = [[NSBundle mainBundle] pathForResource:@"LastName" ofType:@"txt"];
NSLog(@".....%@",resourcePath1);
NSLog(@">>>> %@",resourcePath2);
NSData *firstData = [NSData dataWithContentsOfFile:resourcePath1];
NSData *lastData = [NSData dataWithContentsOfFile:resourcePath2];
NSString *firstStr= [[NSMutableString alloc] initWithData:firstData encoding:NSUTF8StringEncoding];
NSString *lastStr = [[NSMutableString alloc] initWithData:lastData encoding:NSUTF8StringEncoding];
char *Cstring = "\n"; //分割符
NSString *separatedString = [NSString stringWithUTF8String:Cstring];
_FirstNames = [firstStr componentsSeparatedByString:separatedString];
_LastNames = [lastStr componentsSeparatedByString:separatedString];
}
// 点击显示姓名
NSString *firstName = [_FirstNames objectAtIndex:arc4random()%(_FirstNames.count)];
NSString *lastName = [_LastNames objectAtIndex:arc4random()%(_LastNames.count)];
[_nameLabel setText:[NSString stringWithFormat:@"%@%@",firstName,lastName]];
最新文章
- 项目中angular js的接口url统一管理
- 软工实践——github文件整理
- 未定义标识符string
- 关于eclipse中MAVEN WEB工程中编译问题
- 学习 BigInteger
- HTTP Status 404–/webDemo/hello
- 动态 SQL
- ubuntu zend-eclipse-php debugger调试
- Android 自定义View (四) 视频音量调控
- goahead webserver源码分析
- EF使用时异常:对一个或多个实体的验证失败。有关详细信息
- Asp.Net MVC5入门学习
- match in shell scripts
- JavaScript的数组实现队列与堆栈的方法
- Codeforces 812E Sagheer and Apple Tree
- 自定义 ThreadPoolExecutor 处理线程运行时异常
- 3D视图的2D展示
- PHP实用代码片段(三)
- mysql导出长数字到excel避免显示为科学记数法 解决方法
- python魔法方法:__getattr__,__setattr__,__getattribute__