Library contents

Kotlin String.plus

Append one string to another to assemble a printable identifier.

A simple example

String.plus

  1. Start with "a" and "b"
  2. Do this Join end to end
  3. Result "ab"
Both letters appear in the same order, with no separator added.
Lesson.kt
fun main() {
    val value = "a"
    val other = "b"
    println(value + other)
}
Output
ab

Syntax

Kotlin syntax
value + other
Run these examples in Kotlin

Save one example at a time as Lesson.kt. Use Kotlin 2.2 on JDK 21.

kotlinc Lesson.kt -include-runtime -d lesson.jar
java -jar lesson.jar

Attach a seat number to a row

A label printer receives an identifier in separate pieces instead of one finished string. Assemble the pieces in the intended order and check the separator where the two fields meet.

From the programval value = "Row B-"
ResultRow B-12
Lesson.kt
fun main() {
    val value = "Row B-"
    val other = "12"
    println(value + other)
}
Output
Row B-12

The prefix already contains the hyphen.

Advertisements

Add an extension to a receipt

An export routine receives the base name for a receipt. Add the extension to produce the printable filename and keep the original name available for any other export format.

From the programval value = "march"
Resultmarch.pdf
Lesson.kt
fun main() {
    val value = "march"
    val other = ".pdf"
    println(value + other)
}
Output
march.pdf

The extension includes its own leading dot.

Build a parcel shelf identifier

The shelf prefix already includes the hyphen. Combine the two fragments in order without adding another separator. What label goes to the printer?

Given'North-' · '12'
Worked resultNorth-12

What to watch for

Insert any required separator explicitly. Keep the returned text in languages with immutable strings.

Documentation for String.plus