iphone 关于NSString

去除两端空格
NSString *temp = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

去除两端空格和回车
NSString *text = [temp stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];


//nsstring 比较10 和 9的比较,得到的结果9 >10,我们正常理解的情况应该是 10大于9的。实现的代码如下
NSString *lev = @"10";
NSString *cons = @"9";
if ([lev intValue] > [cons intValue]) {
    NSLog(lev,nil);
}//法一
NSString *lev = @"10";
NSString *cons = @"9";
NSComparisonResult newrecord = [lev compare:cons options:NSNumericSearch];
if (newrecord > 0) {
    NSLog(lev,nil);
}//法二

关于字符串,获得连续的A,B,C等的方式在tableview中,如果想实现连续的展示如下

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"showABC";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
        [label setTag:kLabelTag];
        [cell.contentView addSubview:label];
        [label release];
    }
    UILabel *label = (id)[cell viewWithTag:kLabelTag];
    [label setText:[NSString stringWithFormat:@"%c",'A'+indexPath.row]];
    cell.accessoryType = UITableViewCellAccessoryNone;
    return cell;
}
对html字符串的解析简单解析思路
NSRange range;
NSMutableString *mutString = (NSMutableString *)@"<blockquote><font color=#ff0000><font color=#999999>shuguang86 发表于 2013-3-25 20:53</font> <br /><br/>再来灌灌水<br /><br/><img src=/pics/201303/13748/1374845/thumb_1374845_1364216012.jpg border=0></font></blockquote><br /><br/><br /><br/>漂亮!";
int i=0;
while ((range = [mutString rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound){
    range = [mutString rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch];
    [mutary addObject:[mutString substringWithRange:range]];
    mutString = [mutString substringFromIndex:range.length+range.location];
}//获取标签
NSLog(@"%@",mutary);
/*
 2013-03-26 10:45:36.269 ExRghtBrainDevelopment[4183:c07] (
 "<blockquote>",
 "<font color=#ff0000>",
 "<font color=#999999>",
 "</font>",
 "<br />",
 "<br/>",
 "<br />",
 "<br/>",
 "<img src=/pics/201303/13748/1374845/thumb_1374845_1364216012.jpg border=0>",
 "</font>",
 "</blockquote>",
 "<br />",
 "<br/>",
 "<br />",
 "<br/>"
 )
 */



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值