zoukankan      html  css  js  c++  java
  • NSString去除两边空格字符,like trim()[转]

    1. NSString *cleanString = [dirtyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];  

    还有就是去除多于的空格,如下:

    1. NSString *theString = @"    Hello      this  is a   long       string!   ";  
    2.   
    3. NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet];  
    4. NSPredicate *noEmptyStrings = [NSPredicate predicateWithFormat:@"SELF != ''"];  
    5.   
    6. NSArray *parts = [theString componentsSeparatedByCharactersInSet:whitespaces];  
    7. NSArray *filteredArray = [parts filteredArrayUsingPredicate:noEmptyStrings];  
    8. theString = [filteredArray componentsJoinedByString:@" "];  
  • 相关阅读:
    Arctic Network POJ
    Journey CodeForces
    Free Goodies UVA
    MU Puzzle HDU
    Balance POJ
    1sting 大数 递推
    最大报销额 暴力。。
    洛谷P2826 LJJ的数学课
    2018年12月29日
    2018年12月28日
  • 原文地址:https://www.cnblogs.com/zhkza99c/p/3794647.html
Copyright © 2011-2022 走看看