/**
 * Given a string, an index position, and a replacement string, modify the original string by replacing the character
 * at the given index position with the replacement string.
 *
 * @param string The original string.
 * @param index The index position of the character to be replaced.
 * @param replacement The string to replace the character at the given index.
 * @return The modified string.
 * @throws IndexOutOfBoundsException If the index is out of range.
 */
fun modifyStringElements(string: String, index: Int, replacement: String): String {

    if (index < 0 || index >= string.length) {
        throw IndexOutOfBoundsException("Index out of range")
    }

    // Convert the string to a CharArray for easier modification
    val stringArray = string.toCharArray()

    // Replace the character at the given index with the replacement string
    stringArray[index] = replacement.single()

    // Convert the CharArray back to a string
    return String(stringArray)
}
/**
 * Given a string, an index position, and a replacement string, modify the original string by replacing the character
 * at the given index position with the replacement string.
 *
 * @param string The original string.
 * @param index The index position of the character to be replaced.
 * @param replacement The string to replace the character at the given index.
 * @return The modified string.
 * @throws IndexOutOfBoundsException If the index is out of range.
 */
fun modifyStringElements(string: String, index: Int, replacement: String): String {
/**
 * Given a string, an index position, and a replacement string, modify the original string by replacing the character
 * at the given index position with the replacement string.
 *
 * @param string The original string.
 * @param index The index position of the character to be replaced.
 * @param replacement The string to replace the character at the given index.
 * @return The modified string.
 * @throws IndexOutOfBoundsException If the index is out of range.
 */
fun modifyStringElements(string: String, index: Int, replacement: String): String {

    if (index < 0 || index >= string.length) {
        throw IndexOutOfBoundsException("Index out of range")
    }

    // Convert the string to a CharArray for easier modification
    val stringArray = string.toCharArray()

    // Replace the character at the given index with the replacement string
    stringArray[index] = replacement.single()

    // Convert the CharArray back to a string
    return String(stringArray)
}