There is a variable of type string in it html code

 var htmlString = "<img alt=\"\" src=\"/wp-content/uploads/2015/10/swift-big.jpg" style=\"height:326px; margin:10px; width:563px\" />" 

The bottom line is that before "/wp-content/uploads/2015/10/swift-big.jpg" I need to insert https://www.iphones.ru , that is, after src=\"
How can I do it?

    1 answer 1

    Considering that you are working with Wordpress and are clearly solving a local task (not universal), the simplest option is to use a replacement:

     var htmlString = "<img alt=\"\" src=\"/wp-content/uploads/2015/10/swift-big.jpg\" style=\"height:326px; margin:10px; width:563px\" />" let domain = "https://www.iphones.ru" let textForFind = "src=\"/wp-content/uploads/" let textForReplace = "src=\"\(domain)/wp-content/uploads/" htmlString = htmlString.replacingOccurrences(of: textForFind, with: textForReplace) print(htmlString) 

    If the task is to make a more universal code, you can search for src = \ "using let range = htmlString.range (of:" src = \ ""), then cut the text before and after src = \ "and add the domain when gluing.