/**
 * Given a string, replace a specific portion of the string with a new value.
 *
 * @param string The original string.
 * @param startIndex The starting index of the portion to be replaced.
 * @param endIndex The ending index of the portion to be replaced.
 * @param newValue The new value to replace the portion with.
 * @return The modified string with the specified portion replaced.
 *
 * Example:
 * sliceAndReplaceElements("Hello World", 6, 11, "Freya")
 * Output: "Hello Freya"
 */
fun sliceAndReplaceElements(string: String, startIndex: Int, endIndex: Int, newValue: String): String {

    // Get the portion of the string to be replaced
    val portionToReplace = string.substring(startIndex, endIndex)

    // Replace the portion with the new value
    val newString = string.substring(0, startIndex) + newValue + string.substring(endIndex)

    return newString
}
/**
 * Given a string, replace a specific portion of the string with a new value.
 *
 * @param string The original string.
 * @param startIndex The starting index of the portion to be replaced.
 * @param endIndex The ending index of the portion to be replaced.
 * @param newValue The new value to replace the portion with.
 * @return The modified string with the specified portion replaced.
 *
 * Example:
 * sliceAndReplaceElements("Hello World", 6, 11, "Freya")
 * Output: "Hello Freya"
 */
fun sliceAndReplaceElements(string: String, startIndex: Int, endIndex: Int, newValue: String): String {
/**
 * Given a string, replace a specific portion of the string with a new value.
 *
 * @param string The original string.
 * @param startIndex The starting index of the portion to be replaced.
 * @param endIndex The ending index of the portion to be replaced.
 * @param newValue The new value to replace the portion with.
 * @return The modified string with the specified portion replaced.
 *
 * Example:
 * sliceAndReplaceElements("Hello World", 6, 11, "Freya")
 * Output: "Hello Freya"
 */
fun sliceAndReplaceElements(string: String, startIndex: Int, endIndex: Int, newValue: String): String {

    // Get the portion of the string to be replaced
    val portionToReplace = string.substring(startIndex, endIndex)

    // Replace the portion with the new value
    val newString = string.substring(0, startIndex) + newValue + string.substring(endIndex)

    return newString
}