Remove All Whitespace in Kotlin

Published on 06 October 2025 (Updated: 06 October 2025)

Welcome to the Remove All Whitespace in Kotlin page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

import kotlin.system.exitProcess

fun main(args: Array<String>) {
    val phrase: String = errorChecking(args)
    println(removeWhitespace(phrase))
}

fun usageError() {
    println("Usage: please provide a string")
}

fun errorChecking(args: Array<String>): String {
    if (args.size == 0 || args[0] == "") {
       usageError()
       exitProcess(1)
    }
    return args[0]
}

fun removeWhitespace(phrase: String): String {
    return phrase.filter { !it.isWhitespace() }
}

Remove All Whitespace in Kotlin was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.