/**
 * Given a string and a character, this function should replace all occurrences of the character with its index in the string,
 * and return the modified string.
 *
 * Example:
 * ----------
 * Input:
 * string = "hello world"
 * char = 'o'
 *
 * Output:
 * "hell1 w2rld"
 *
 * Note:
 * ------
 * - The index starts from 0.
 * - The character to be replaced can occur multiple times in the string.
 * - The modified string should retain its original case.
 * - If the character is not present in the string, the function should return the original string.
 */
fun manipulateString(string: String, char: Char): String {

    // Use mapIndexed to replace the character with its index
    val modifiedString = string.mapIndexed { index, ch ->
        if (ch.equals(char, ignoreCase = true)) {
            index.toString()
        } else {
            ch.toString()
        }
    }.joinToString("")

    return modifiedString
}
/**
 * Given a string and a character, this function should replace all occurrences of the character with its index in the string,
 * and return the modified string.
 *
 * Example:
 * ----------
 * Input:
 * string = "hello world"
 * char = 'o'
 *
 * Output:
 * "hell1 w2rld"
 *
 * Note:
 * ------
 * - The index starts from 0.
 * - The character to be replaced can occur multiple times in the string.
 * - The modified string should retain its original case.
 * - If the character is not present in the string, the function should return the original string.
 */
fun manipulateString(string: String, char: Char): String {
/**
 * Given a string and a character, this function should replace all occurrences of the character with its index in the string,
 * and return the modified string.
 *
 * Example:
 * ----------
 * Input:
 * string = "hello world"
 * char = 'o'
 *
 * Output:
 * "hell1 w2rld"
 *
 * Note:
 * ------
 * - The index starts from 0.
 * - The character to be replaced can occur multiple times in the string.
 * - The modified string should retain its original case.
 * - If the character is not present in the string, the function should return the original string.
 */
fun manipulateString(string: String, char: Char): String {

    // Use mapIndexed to replace the character with its index
    val modifiedString = string.mapIndexed { index, ch ->
        if (ch.equals(char, ignoreCase = true)) {
            index.toString()
        } else {
            ch.toString()
        }
    }.joinToString("")

    return modifiedString
}