/**
 * Given a string, replace a specific range of elements with a given replacement substring using string slicing.
 *
 * @param string The original string.
 * @param start The starting index of the range to be replaced.
 * @param end The ending index of the range to be replaced.
 * @param replacement The substring to replace the specified range of elements.
 * @return The modified string with the range of elements replaced.
 *
 * Example:
 * replaceElements("Hello, world!", 7, 12, "Jina") -> "Hello, Jina!"
 *
 * Note:
 * - The starting index is inclusive and the ending index is exclusive.
 * - The indices can be negative, representing counting from the end of the string.
 * - If the start is greater than or equal to the end, the string remains unchanged.
 */
fun replaceElements(string: String, start: Int, end: Int, replacement: String): String {

    if (start >= end) {
        return string
    }
    
    return string.substring(0, start) + replacement + string.substring(end)
}
/**
 * Given a string, replace a specific range of elements with a given replacement substring using string slicing.
 *
 * @param string The original string.
 * @param start The starting index of the range to be replaced.
 * @param end The ending index of the range to be replaced.
 * @param replacement The substring to replace the specified range of elements.
 * @return The modified string with the range of elements replaced.
 *
 * Example:
 * replaceElements("Hello, world!", 7, 12, "Jina") -> "Hello, Jina!"
 *
 * Note:
 * - The starting index is inclusive and the ending index is exclusive.
 * - The indices can be negative, representing counting from the end of the string.
 * - If the start is greater than or equal to the end, the string remains unchanged.
 */
fun replaceElements(string: String, start: Int, end: Int, replacement: String): String {
/**
 * Given a string, replace a specific range of elements with a given replacement substring using string slicing.
 *
 * @param string The original string.
 * @param start The starting index of the range to be replaced.
 * @param end The ending index of the range to be replaced.
 * @param replacement The substring to replace the specified range of elements.
 * @return The modified string with the range of elements replaced.
 *
 * Example:
 * replaceElements("Hello, world!", 7, 12, "Jina") -> "Hello, Jina!"
 *
 * Note:
 * - The starting index is inclusive and the ending index is exclusive.
 * - The indices can be negative, representing counting from the end of the string.
 * - If the start is greater than or equal to the end, the string remains unchanged.
 */
fun replaceElements(string: String, start: Int, end: Int, replacement: String): String {

    if (start >= end) {
        return string
    }
    
    return string.substring(0, start) + replacement + string.substring(end)
}