2017-04-18 92 views
1

我怎麼能代替這個字符串用另一個不管的值是否是2或4或5替換字符串值

<font size=\"2\" 

我現在:

replacingOccurrences(of: "font size=\"2\"", with: "font size=\"4\"") 

但2默認情況下不會總是到達。

+0

一個NSRegularExpression可以做的伎倆。 – Larme

回答

2

您可以使用replacingOccurrences(of:with:options:range:).regularExpression選項。

let str = "<font size=\"3\"" 
print(str.replacingOccurrences(of: "(font size=\"[0-9]+\")", with: "font size=\"4\"", options: .regularExpression)) 
<font size="4" 
+0

非常感謝! – Alejandro