返回顶部

收藏

Objective-C字符串操作

更多
void testString(){
    // String str = "banxi1988";
    NSString* str = @"banxi1988";
    NSString* bstr = @"banxi1988";
    // str.equals(bstr);
    BOOL same = [str isEqualToString:bstr];
    NSLog(@"isSame:%d",same);
    // str.startsWith("banxi");
    BOOL hasPrefix = [str hasPrefix:@"banxi"];
    NSLog(@"hasPrefix:%d",hasPrefix);
    // str.length()
    NSLog(@"str length:%lu",[str length]);
    // str.charAt(int)
    NSLog(@"char at 1:%hu",[str characterAtIndex:1]);
    NSLog(@"compare:%ld",[str compare:@"banxi1989"]);
    // str.compareToIgnoreCase(String)
    NSLog(@"compareInsensitive:%ld",[str caseInsensitiveCompare:@"BANXI1988"]);
    // str.toUpperCase()
    NSLog(@"uppercaseString:%@",[str uppercaseString]);
    // str.toLowerCase()
    NSLog(@"lowercaseString:%@",[@"BANXI" lowercaseString]);
    // str.substring(int)
    NSLog(@"substringFromIndex:%@",[str substringFromIndex:1]);
    // str.substring(int, int)
    NSLog(@"substringWithRange:%@", [str substringWithRange:NSMakeRange(0, 2)]);
    NSLog(@"stringByTrimmingCharactersInSet:%@",[@" banxi " stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]);
    // String.format(String,Object...)
    NSLog(@"stringWithFormat:%@",[NSString stringWithFormat: @"%d is less than %@",3,@"yes"]);
    // str.concat(String)
    NSLog(@"stringByAppendingString:%@",[str stringByAppendingString:@"@gmail.com"]);
}
//该片段来自于http://outofmemory.cn

标签:c++,手机开发

收藏

0人收藏

支持

0

反对

0

相关聚客文章
  1. coder4 发表 2013-02-02 15:15:20 c++ tr1和Boost中,tuple、tie的用法。
  2. Scott Meyers 发表 2011-04-01 05:32:02 Appearing and Disappearing consts in C++
  3. Herb Sutter 发表 2012-04-30 21:59:18 World’s youngest C++ programmer?
  4. Herb Sutter 发表 2012-09-12 19:00:39 VC++ 2012 Desktop Express (Free)
  5. Herb Sutter 发表 2013-01-16 00:08:30 Java vulnerabilities
  6. Andy Rich 发表 2013-03-04 23:04:00 Connecting to Live with the C++ REST SDK
  7. bystander 发表 2013-04-11 10:50:25 模板栈以及中缀表达式求值(C++实现)
  8. 博主 发表 2009-10-18 16:00:00 配置 Vim 作为 C++ 开发环境初步
  9. Sana Mithani 发表 2013-06-04 18:11:00 C++ REST SDK 1.0.0 is now available
  10. admin 发表 2012-07-28 06:44:59 STL库的for each支持
  11. ideawu 发表 2013-08-09 16:28:15 WebRTC C/C++ API 示例代码 – 播放和录音
  12. coder4 发表 2013-09-23 06:00:08 C++中,解析UTF-8字符的位置。

发表评论