去除两端空格
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/>" ) */