【发布时间】:2018-06-17 18:14:03
【问题描述】:
我有一个这样的字符串:
"te_st" 并喜欢将 all underscores followed by a character 替换为该字符的大写版本。
来自"te_st" --> 找到(正则表达式:"_.")--------替换为下一个字符(+大写字母("s"->"S")-------- -> "teSt"
从"te_st" ---> 到"teSt"
从"_he_l_lo" ---> 到"HeLLo"
从"an_o_t_h_er_strin_g" ---> 到"anOTHErStrinG"
...但我无法真正使用 Swift 的 NSRegularExpression 来让它工作,就像这个小片段一样:
var result = "te_st" // result should be teSt
result = try! NSRegularExpression(pattern: "_*").stringByReplacingMatches(in: result, range: NSRange(0..<result.count), withTemplate: ("$1".uppercased()))
【问题讨论】: