Savage F. Morgan

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

How to check if NSString begins with a certain character

How do you check if an NSString begins with a certain character (the character *).

The * is an indicator for the type of the cell, so I need the contents of this NSString without the *, but need to know if the * exists.

You can use the -hasPrefix: method of NSString:

NSString* output = nil;
if([string hasPrefix:@"*"])
    output = [string substringFromIndex:1];

 

posted on 2014-07-14 14:36  罗斯摩根  阅读(208)  评论(0编辑  收藏  举报