/**
 * In this exercise, you need to write a function that replaces all occurrences of a specific word
 * with a new word in a given text. You must use a combination of a while loop and a for loop.
 *
 * @param text The original text where the replacements will be performed.
 * @param oldWord The word that needs to be replaced.
 * @param newWord The new word that will replace the oldWord.
 * @return The updated text with the replacements made.
 *
 * Example:
 * replaceText("Hello world, hello universe!", "hello", "goodbye")  // Output: "Goodbye world, goodbye universe!"
 */
fun replaceText(text: String, oldWord: String, newWord: String): String {

    var result = ""
    var index = 0
    while (index < text.length) {
        var found = false
        for (i in index until text.length) {
            if (text.substring(i, i + oldWord.length).equals(oldWord, ignoreCase = true)) {
                result += newWord
                index = i + oldWord.length
                found = true
                break
            }
        }
        if (!found) {
            result += text[index]
            index++
        }
    }
    return result
}
/**
 * In this exercise, you need to write a function that replaces all occurrences of a specific word
 * with a new word in a given text. You must use a combination of a while loop and a for loop.
 *
 * @param text The original text where the replacements will be performed.
 * @param oldWord The word that needs to be replaced.
 * @param newWord The new word that will replace the oldWord.
 * @return The updated text with the replacements made.
 *
 * Example:
 * replaceText("Hello world, hello universe!", "hello", "goodbye")  // Output: "Goodbye world, goodbye universe!"
 */
fun replaceText(text: String, oldWord: String, newWord: String): String {
/**
 * In this exercise, you need to write a function that replaces all occurrences of a specific word
 * with a new word in a given text. You must use a combination of a while loop and a for loop.
 *
 * @param text The original text where the replacements will be performed.
 * @param oldWord The word that needs to be replaced.
 * @param newWord The new word that will replace the oldWord.
 * @return The updated text with the replacements made.
 *
 * Example:
 * replaceText("Hello world, hello universe!", "hello", "goodbye")  // Output: "Goodbye world, goodbye universe!"
 */
fun replaceText(text: String, oldWord: String, newWord: String): String {

    var result = ""
    var index = 0
    while (index < text.length) {
        var found = false
        for (i in index until text.length) {
            if (text.substring(i, i + oldWord.length).equals(oldWord, ignoreCase = true)) {
                result += newWord
                index = i + oldWord.length
                found = true
                break
            }
        }
        if (!found) {
            result += text[index]
            index++
        }
    }
    return result
}