How to replace a substring with a link(http) in swift 3? -


i have string , substring(http) , want replace substring don't know when substring end. mean want check until 1 space not coming , after want replace it. checking if string contains http string want replace when space come.

here below example :-

let string = "hello.world http://www.google.com way good".  

this string can dynamic mean in above string http there, want replace "http://www.google.com" "website".

string = "hello.world website way good" 

a possible solution regular expression

the pattern searches http:// or https:// followed 1 or more non-whitespace characters word boundary.

let string = "hello.world http://www.google.com way good" let trimmedstring = string.replacingoccurrences(of: "https?://\\s+\\b", with: "website", options: .regularexpression) print(trimmedstring) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -