Skip to content

Instantly share code, notes, and snippets.

@chenjunpu
chenjunpu / StringExtensions.swift
Created August 29, 2022 09:21 — forked from mcxiaoke/StringExtensions.swift
replace for Swift String (include replaceFirst and replaceAll), in Swift 3
import Foundation
extension String {
public func replaceFirst(of pattern:String,
with replacement:String) -> String {
if let range = self.range(of: pattern){
return self.replacingCharacters(in: range, with: replacement)
}else{
return self