/**
 * Given an input string, an index, and a new character, this function replaces the character
 * at the specified index with the new character and returns the modified string.
 *
 * @param inputString The original input string.
 * @param index Index of the character to be replaced.
 * @param newCharacter The new character to replace the existing one.
 * @return The modified string with the character replaced.
 */
fun modifyString(inputString: String, index: Int, newCharacter: Char): String {

    // Convert string to mutable list
    val stringList = inputString.toMutableList()

    // Replace character at specified index with new character
    stringList[index] = newCharacter

    // Join the modified list back to a string
    val modifiedString = stringList.joinToString("")

    return modifiedString
}

// Exercise: Modify the string at a given index
val targetString = "anthropology"
val targetIndex = 6 // Index at which the character will be replaced
val newChar = 'i' // New character to replace the existing one

// Call the function to modify the string
val modifiedString = modifyString(targetString, targetIndex, newChar)
/**
 * Given an input string, an index, and a new character, this function replaces the character
 * at the specified index with the new character and returns the modified string.
 *
 * @param inputString The original input string.
 * @param index Index of the character to be replaced.
 * @param newCharacter The new character to replace the existing one.
 * @return The modified string with the character replaced.
 */
fun modifyString(inputString: String, index: Int, newCharacter: Char): String {
/**
 * Given an input string, an index, and a new character, this function replaces the character
 * at the specified index with the new character and returns the modified string.
 *
 * @param inputString The original input string.
 * @param index Index of the character to be replaced.
 * @param newCharacter The new character to replace the existing one.
 * @return The modified string with the character replaced.
 */
fun modifyString(inputString: String, index: Int, newCharacter: Char): String {

    // Convert string to mutable list
    val stringList = inputString.toMutableList()

    // Replace character at specified index with new character
    stringList[index] = newCharacter

    // Join the modified list back to a string
    val modifiedString = stringList.joinToString("")

    return modifiedString
}

// Exercise: Modify the string at a given index
val targetString = "anthropology"
val targetIndex = 6 // Index at which the character will be replaced
val newChar = 'i' // New character to replace the existing one

// Call the function to modify the string
val modifiedString = modifyString(targetString, targetIndex, newChar)