/**
 * This function takes a string and trims it to a specified length by removing characters from both ends until the length is reached.
 * If the length is not divisible by 2, the function will favor the right side by removing an extra character.
 *
 * @param string The input string to be trimmed
 * @param length The desired length of the trimmed string
 * @return The trimmed string
 *
 * Example:
 * input: "pythoncode"
 * length: 8
 * output: "thond"
 */
fun trimString(string: String, length: Int): String {

    if (string.length <= length) {
        return string
    }

    val trimLength = string.length - length
    val halfTrim = trimLength / 2
    val extraTrim = trimLength % 2

    val leftIndex = halfTrim
    var rightIndex = string.length - halfTrim

    if (extraTrim == 1) {
        rightIndex -= 1
    }

    return string.substring(leftIndex, rightIndex)
}
/**
 * This function takes a string and trims it to a specified length by removing characters from both ends until the length is reached.
 * If the length is not divisible by 2, the function will favor the right side by removing an extra character.
 *
 * @param string The input string to be trimmed
 * @param length The desired length of the trimmed string
 * @return The trimmed string
 *
 * Example:
 * input: "pythoncode"
 * length: 8
 * output: "thond"
 */
fun trimString(string: String, length: Int): String {
/**
 * This function takes a string and trims it to a specified length by removing characters from both ends until the length is reached.
 * If the length is not divisible by 2, the function will favor the right side by removing an extra character.
 *
 * @param string The input string to be trimmed
 * @param length The desired length of the trimmed string
 * @return The trimmed string
 *
 * Example:
 * input: "pythoncode"
 * length: 8
 * output: "thond"
 */
fun trimString(string: String, length: Int): String {

    if (string.length <= length) {
        return string
    }

    val trimLength = string.length - length
    val halfTrim = trimLength / 2
    val extraTrim = trimLength % 2

    val leftIndex = halfTrim
    var rightIndex = string.length - halfTrim

    if (extraTrim == 1) {
        rightIndex -= 1
    }

    return string.substring(leftIndex, rightIndex)
}