padEnd
所在位置是kotlin.text.padEnd
,其相关用法介绍如下。
用法一
返回一个字符序列,该字符序列的内容在末尾填充到指定的length,并带有指定的字符或空格。
例子:
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//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
}
输出:
'125 ' 'a....' 'abcde'
参数
padChar
- 填充字符串的字符,如果它的长度小于长度指定的。默认使用空间。
返回 返回长度至少为 length 的字符序列,该序列由 this
字符序列附加 padChar 组成,次数达到该长度所需的次数。
用法二
用指定的字符或空格将字符串填充到指定的length 末尾。
例子:
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//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
}
输出:
'125 ' 'a....' 'abcde'
参数
padChar
- 填充字符串的字符,如果它的长度小于长度指定的。默认使用空间。
返回返回长度至少为length 的字符串,该字符串由this
字符串和padChar 组成,其次数达到该长度所需的次数。
相关用法
- Kotlin padStart用法及代码示例
- Kotlin partition用法及代码示例
- Kotlin plus用法及代码示例
- Kotlin associateBy用法及代码示例
- Kotlin all用法及代码示例
- Kotlin map用法及代码示例
- Kotlin filterNot用法及代码示例
- Kotlin reduceRight用法及代码示例
- Kotlin Random.Default用法及代码示例
- Kotlin Byte.inc用法及代码示例
- Kotlin getValue用法及代码示例
- Kotlin Double.dec用法及代码示例
- Kotlin windowedSequence用法及代码示例
- Kotlin contentToString用法及代码示例
- Kotlin groupByTo用法及代码示例
- Kotlin commonPrefixWith用法及代码示例
- Kotlin MatchResult.Destructured用法及代码示例
- Kotlin Delegates.notNull用法及代码示例
- Kotlin ifBlank用法及代码示例
- Kotlin filterNotTo用法及代码示例
- Kotlin getOrPut用法及代码示例
- Kotlin Triple.<init>用法及代码示例
- Kotlin Duration.toString用法及代码示例
- Kotlin windowed用法及代码示例
- Kotlin indexOf用法及代码示例
注:本文由纯净天空筛选整理自kotlinlang.org大神的英文原创作品 kotlin.text.padEnd。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。