zoukankan      html  css  js  c++  java
  • 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 = " ";    //分割符

        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]];

  • 相关阅读:
    JS中的getter与setter
    Node.js中exports与module.exports的区别
    JS中的匿名函数自执行、函数声明与函数表达式
    JS实现千分位
    JS中的new操作符原理解析
    JS中null与undefined的区别
    JavaScript中callee与caller,apply与call解析
    解决vue路由与锚点冲突
    jQuery中deferred的对象使用
    Vue的生命周期
  • 原文地址:https://www.cnblogs.com/XHShare/p/4953309.html
Copyright © 2011-2022 走看看