【问题标题】:How to remove characters from an NSString and replace with spaces? [duplicate]如何从 NSString 中删除字符并替换为空格? [复制]
【发布时间】:2014-04-24 07:35:09
【问题描述】:

我有一个 NSString:

NSString *string1 = @"http://example.com/this-is-an-example-post"

通过删除一系列字符,我将其子字符串化为:

NSString *string2 = @"this-is-an-example-post"

但我正在努力将其转化为:

NSString *string3 = @"this is an example post"

有什么帮助吗?非常感谢。

【问题讨论】:

  • stringByReplacingOccurrencesOfString: withString:

标签: ios objective-c nsstring nsrange


【解决方案1】:

例如这样

string3 = [string2 stringByReplacingOccurrencesOfString:@"-" withString:@" "];

【讨论】:

  • @CescSergey:可能是因为简单查找 NSString 文档就可以解决您的问题。
猜你喜欢
  • 2018-07-02
  • 2011-04-15
  • 2012-11-19
  • 2020-03-16
  • 2011-07-29
  • 1970-01-01
  • 1970-01-01
  • 2013-12-11
相关资源
最近更新 更多