String literals in Kotlin are capable of string interpolation, and the dollar sign is the start of a string template expression. If you need the literal dollar sign in a string instead, you should escape it using a backslash: \$. So your template (which I assume you're passing to String.format) becomes:

val template = "Something %s something else %s. The first was %1\$s, the second was %2\$s"
Answer from Alexander Udalov on Stack Overflow
🌐
Delft Stack
delftstack.com › home › howto › kotlin › kotlin string format
How to Format String in Kotlin | Delft Stack
February 2, 2024 - There are two ways to format string in Kotlin: the String Templates and String.format() method. String templates allow us to insert variable values and functions returning values directly into String.
🌐
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin.text › format.html
format - Kotlin Programming Language
August 9, 2023 - See java.util.Formatter class documentation for the syntax of format specifiers for the format string. import java.util.Locale import kotlin.test.* fun main(args: Array<String>) { //sampleStart // format with German conventions val withGermanThousandsSeparator = "%,d".format(Locale.GERMANY, 12345) println(withGermanThousandsSeparator) // 12.345 // 12.345 // format with US conventions val withUSThousandsSeparator = "%,d".format(Locale.US, 12345) println(withUSThousandsSeparator) // 12,345 //sampleEnd }
🌐
Stonesoupprogramming
stonesoupprogramming.com › 2017 › 11 › 17 › kotlin-string-formatting
Kotlin String Formatting – Stone Soup Programming
November 6, 2017 - String formatting allows developers to define a common string template and then interchange values as needed. Kotlin has a feature known as String Templates that allow you specify a string and then reference variables as required.
🌐
Jonas-rodehorst
jonas-rodehorst.dev › blog › koltin-string-formatting
Kotlin String Formatting with Examples
November 18, 2022 - Make sure that both the number and the order of the parameters and the placeholders match. In this way, a longer string is assembled. The assignment of this string results in the output on the console. Here's a full list of specifier types for the format function you can use in Kotlin:
🌐
Kotlin
kotlinlang.org › docs › strings.html
Strings | Kotlin Documentation
February 4, 2026 - Common format specifiers include %d for integers, %f for floating-point numbers, and %s for strings. You can also use the argument_index$ syntax to reference the same argument multiple times within the format string in different formats.
🌐
Programiz
programiz.com › kotlin-programming › string
Kotlin String and String Templates (With Examples)
Length of s1 string is 10. Strings s1 and s2 are equal. Third character is y. result = Hey there! How are you? Substring is "the" Visit Kotlin String class for more information on extension properties, extension, functions and constructors.
🌐
Spark By {Examples}
sparkbyexamples.com › home › kotlin › format string in kotlin with examples
Format String in Kotlin With Examples - Spark By {Examples}
May 9, 2024 - How to format a string in Kothin? Formatting string is a standard operation in most programming languages, including Kotlin. In Kotlin, you can use the
Find elsewhere
🌐
Kotlin Discussions
discuss.kotlinlang.org › t › java-string-format-alternative-in-kotlin › 703
Java String.format alternative in kotlin? - Kotlin Discussions
November 18, 2013 - Hi, I’m using java String.format in my codes which i want to port to kotlin. For example String log = String.format(“%d, %s, o : ?”, value1, value2, value3, value4) How to convert above java code to kotlin? Than…
🌐
sebhastian
sebhastian.com › kotlin-string-format
Kotlin String format() method example | sebhastian
January 3, 2022 - Like in Java, the first argument of the format() function will be the string format, while the rest would be the values to put into the string.
🌐
Kotlin
kotlinlang.org › docs › java-to-kotlin-idioms-strings.html
Strings in Java and Kotlin | Kotlin Documentation
November 13, 2025 - In Java, to split a string with ...s.text.should.be.split".split("\\."))); In Kotlin, use the Kotlin function split(), which accepts varargs of delimiters as input parameters:...
🌐
Android Developers
developer.android.com › api reference › formatter
Formatter | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.text › format.html
format | Core API – Kotlin Programming Language
See java.util.Formatter class documentation for the syntax of format specifiers for the format string. ... import kotlin.test.* import java.util.* import java.util.regex.* fun main() { //sampleStart // format negative number in parentheses val negativeNumberInParentheses = "%(d means %1\$d".format(-31416) println(negativeNumberInParentheses) // (31416) means -31416 //sampleEnd }
🌐
Baeldung
baeldung.com › home › kotlin › kotlin numbers › number formatting in kotlin
Number Formatting in Kotlin | Baeldung on Kotlin
March 26, 2025 - We can easily build a method in Kotlin that invokes the Java method to convert a Kotlin Double number to a String: fun usingJavaStringFormat(input: Double, scale: Int) = String.format("%.${scale}f", input) As the code above shows, the usingJavaStringFormat method receives two parameters, the Double number input, and the scale.
🌐
Kotlin Discussions
discuss.kotlinlang.org › support
Kotlin String.format - Support - Kotlin Discussions
April 4, 2016 - Hi all I am working on a Kotlin port of the Android Timber library for a quick introductory project. I have encountered an issue with (my use of?) the Kotlin standard lib. I am trying to use String.format with varargs. internal fun prepareLog(priority: Int, t: Throwable?, message: String, vararg args: Any?)
🌐
DhiWise
dhiwise.com › post › kotlin-string-interpolation-explained-techniques-and-examples
Mastering Kotlin String Interpolation
July 10, 2024 - Here’s an example demonstrating the use of a raw string with interpolation: ... 1val userName = "Alice" 2val query = """ 3 SELECT * FROM users 4 WHERE name = "$userName" 5 ORDER BY id DESC 6""" 7println(query) ... Kotlin provides several formatting options to customize the appearance of ...
🌐
DhiWise
dhiwise.com › post › mastering-kotlin-string-formatting-what-you-need-to-know
Mastering Kotlin String Formatting: A Beginner's Guide
September 27, 2024 - You'll also explore how to manipulate and display string values and work with floating point numbers, integers, and other types of data in Kotlin. String formatting in Kotlin involves manipulating and structuring string values to meet specific requirements. This can include adding variables ...
🌐
Baeldung
baeldung.com › home › kotlin › kotlin strings › kotlin string templates
Kotlin String Templates | Baeldung on Kotlin
March 19, 2024 - Notice that inside the curly brackets there’s a valid Kotlin expression. This is a reason why we don’t escape the nested double-quotes. String templates are resolved by evaluating the expression and invoking a toString() method on the result of the evaluation.
🌐
JetBrains
plugins.jetbrains.com › plugin › 18563-replace-string-format-with-kotlin-string-template
Replace String.format with Kotlin String Template - IntelliJ IDEs Plugin | Marketplace
Quickly add named parameters to all callers of a Kotlin class, method or file. Using it is easy: Place your cursor in a String.format call in a Kotlin fileSearch for...