如何修剪IOS中字符串中的特定字符?

时间:2016-01-15 04:31:41

标签: objective-c

我的密钥值为:2016-01-13 04:02:20。但只有我想在我的UILabel文本中只显示2016-01-13。怎么做到这一点?有没有办法缩短钥匙的时间?

2 个答案:

答案 0 :(得分:0)

只需你可以这样做,

  <div class="container">
  <div id="mockTextBox">
    What's Happening ?
  </div></br>
  <textarea id="originalTextBox" class="form-control">
  </textarea>
</div>

输出:

enter image description here

答案 1 :(得分:0)

尝试以下:

NSString *YourString = @"2016-01-13 04:02:20";
YourString=[YourString substringToIndex:10];

OR

NSString *YourString = @"2016-01-13 04:02:20";
[YourString substringWithRange: NSMakeRange(0, [YourString rangeOfString:@" "].location)];

OR

NSArray *arrSepValue;
NSString *YourString = @"2016-01-13 04:02:20";
arrSepValue = [YourString componentsSeparatedByString:@" "];

NSString *DateStr=[arrSepValue objectAtIndex:0];