padEnd

fun CharSequence.padEnd(length: Int, padChar: Char = ' '): CharSequence(source)

Returns a char sequence with content of this char sequence padded at the end to the specified length with the specified character or space.

Since Kotlin

1.1

Return

Returns a char sequence of length at least length consisting of this char sequence appended with padChar as many times as are necessary to reach that length.

Parameters

length

the desired string length.

padChar

the character to pad string with, if it has length less than the length specified. Space is used by default.

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   val padWithSpace = "125".padEnd(5)
println("'$padWithSpace'") // '125  '

val padWithChar = "a".padEnd(5, '.')
println("'$padWithChar'") // 'a....'

// string is returned as is, when its length is greater than the specified
val noPadding = "abcde".padEnd(3)
println("'$noPadding'") // 'abcde' 
   //sampleEnd
}

fun String.padEnd(length: Int, padChar: Char = ' '): String(source)

Pads the string to the specified length at the end with the specified character or space.

Since Kotlin

1.1

Return

Returns a string of length at least length consisting of this string appended with padChar as many times as are necessary to reach that length.

Parameters

length

the desired string length.

padChar

the character to pad string with, if it has length less than the length specified. Space is used by default.

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   val padWithSpace = "125".padEnd(5)
println("'$padWithSpace'") // '125  '

val padWithChar = "a".padEnd(5, '.')
println("'$padWithChar'") // 'a....'

// string is returned as is, when its length is greater than the specified
val noPadding = "abcde".padEnd(3)
println("'$noPadding'") // 'abcde' 
   //sampleEnd
}
fun CharSequence.padEnd(length: Int, padChar: Char = ' '): CharSequence(source)

Returns a char sequence with content of this char sequence padded at the end to the specified length with the specified character or space.

Since Kotlin

1.0

Return

Returns a char sequence of length at least length consisting of this char sequence appended with padChar as many times as are necessary to reach that length.

Parameters

length

the desired string length.

padChar

the character to pad string with, if it has length less than the length specified. Space is used by default.

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   val padWithSpace = "125".padEnd(5)
println("'$padWithSpace'") // '125  '

val padWithChar = "a".padEnd(5, '.')
println("'$padWithChar'") // 'a....'

// string is returned as is, when its length is greater than the specified
val noPadding = "abcde".padEnd(3)
println("'$noPadding'") // 'abcde' 
   //sampleEnd
}

fun String.padEnd(length: Int, padChar: Char = ' '): String(source)

Pads the string to the specified length at the end with the specified character or space.

Since Kotlin

1.0

Return

Returns a string of length at least length consisting of this string appended with padChar as many times as are necessary to reach that length.

Parameters

length

the desired string length.

padChar

the character to pad string with, if it has length less than the length specified. Space is used by default.

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   val padWithSpace = "125".padEnd(5)
println("'$padWithSpace'") // '125  '

val padWithChar = "a".padEnd(5, '.')
println("'$padWithChar'") // 'a....'

// string is returned as is, when its length is greater than the specified
val noPadding = "abcde".padEnd(3)
println("'$noPadding'") // 'abcde' 
   //sampleEnd
}