/**
 * Given a text, replace all occurrences of the old word with the new word.
 *
 * @param text The original text.
 * @param oldWord The word to be replaced.
 * @param newWord The word to replace with.
 * @return The modified text with replaced words.
 */
fun replaceWords(text: String, oldWord: String, newWord: String): String {

    var index = 0
    var modifiedText = text

    while (true) {
        index = modifiedText.indexOf(oldWord, index)
        if (index == -1) {
            break
        }
        modifiedText = modifiedText.substring(0, index) + newWord + modifiedText.substring(index + oldWord.length)
        index += newWord.length
    }

    return modifiedText
}
/**
 * Given a text, replace all occurrences of the old word with the new word.
 *
 * @param text The original text.
 * @param oldWord The word to be replaced.
 * @param newWord The word to replace with.
 * @return The modified text with replaced words.
 */
fun replaceWords(text: String, oldWord: String, newWord: String): String {
/**
 * Given a text, replace all occurrences of the old word with the new word.
 *
 * @param text The original text.
 * @param oldWord The word to be replaced.
 * @param newWord The word to replace with.
 * @return The modified text with replaced words.
 */
fun replaceWords(text: String, oldWord: String, newWord: String): String {

    var index = 0
    var modifiedText = text

    while (true) {
        index = modifiedText.indexOf(oldWord, index)
        if (index == -1) {
            break
        }
        modifiedText = modifiedText.substring(0, index) + newWord + modifiedText.substring(index + oldWord.length)
        index += newWord.length
    }

    return modifiedText
}