 <p>i'm sure there are more elegant solutions but maybe it helps:</p> <pre><code>var myString = "___" myString = "1__" let input = "6" for index in 0 ..&lt; myString.characters.count { let startIndex = myString.startIndex.advancedBy(index) let endIndex = startIndex.advancedBy(1) let range = startIndex..&lt;endIndex let substring = myString[range] if substring == "_" { myString = myString.stringByReplacingCharactersInRange(range, withString: input) break } } </code></pre>