­
  • Home
  • About
  • Our Apps
  • Learn
  • Contact
Login

Register

Login
Seemu Apps Seemu Apps
  • Home
  • About
  • Our Apps
  • Learn
  • Contact

    Replace occurrences of a character in a String

    Home ios Replace occurrences of a character in a String

    Replace occurrences of a character in a String

    May 6, 2016 | Posted by Andrew | ios, swift, tutorial, xcode |

    Replacing a certain occurrence of a character in a string, for example a space(” “) is simple in Swift. Simply use the code below and substitute stringByReplacingOccurencesOfString(” “, withString: “+”) with the character you want to replace with a different character.

            let myString: String = "This is my string"
            let newString = myString.replacingOccurrences(of: " ", with: "+")
            
            print(myString)
            print(newString)

    This will output the following:

    This is my string
    This+is+my+string

    Easy!

    DownloadSourceCode

     

    Tags: characteroccurancesreplacestring
    1
    Share

    About Andrew

    Andrew is a 24 year old from Sydney. He loves developing iOS apps and has done so for two years.

    You also might be interested in

    Swift Optical Character Recognition Tutorial

    May 12, 2018

    By the end of this tutorial you will be able[...]

    Get nth character of a String & get a Substring from a String

    Apr 18, 2016

    To get n character of a String in Swift you[...]

    Split String into Array by Words

    Apr 5, 2016

    Splitting a string into an array based on the word[...]

    Welcome

    Hi I am Andrew and welcome to Seemu Apps! Have a look around, we provide tutorials for primarily iOS apps.
    Bluehost website hosting discount

    Seemu’s Studio Setup

    Blue Yeti Microphone
    Rode Stand
    Spider Shock Mount
    Mac Keyboard Cover
    Screenflow - recording software

    Contact Us

    We're currently offline. Send us an email and we'll get back to you, asap.

    Send Message

    Footer

    :)

    © 2025 · Your Website. Theme by HB-Themes.

    • Home
    • About
    • Our Apps
    • Learn
    • Contact
    Prev Next