# Kotlin String.format

**URL:** <https://discuss.kotlinlang.org/t/kotlin-string-format/1577>\
**Category:** Support\
**Created:** [April 4, 2016, 2:10am UTC](https://discuss.kotlinlang.org/t/kotlin-string-format/1577 "2016-04-04T02:10:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elwesties](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/elwesties/32/1909_2.png) [@elwesties](https://discuss.kotlinlang.org/u/elwesties)\
**Post date:** [April 4, 2016, 2:10am UTC](https://discuss.kotlinlang.org/t/kotlin-string-format/1577/1 "2016-04-04T02:10:18Z")

</div>

Hi all

I am working on a [Kotlin port of the Android Timber library](https://github.com/mitchell-johnson/kimber) 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?) {
       var outputMessage:String = message;
        if (!isLoggable(priority)) {
            return
        }

        if (outputMessage.length == 0) {
            if (t == null) {
                return // Swallow message if it's null and there's no throwable.
            }
            outputMessage = getStackTraceString(t)
        } else {
            if (args.size > 0) {
                outputMessage.format(message, args)
            }
            if (t != null) {
                outputMessage += "\n" + getStackTraceString(t)
            }
        }

        log(priority, getTag(), outputMessage, t)
    }

```

However when I run this function I get the output `Verbose message test [Ljava.lang.Object;@1878709` when calling the function with `Verbose message test %s , "test"`

Any thoughts on how I can make this work? It seems to work as designed if I call the method directly it seems to function as expected.

---

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [April 4, 2016, 7:11am UTC](https://discuss.kotlinlang.org/t/kotlin-string-format/1577/2 "2016-04-04T07:11:49Z")

</div>

You need to use the spread operator to pass a varargs argument to another method that takes a varargs parameter: `outputMessage.format(message, *args)`

---

<div class="post-metadata">

**Author:** ![elwesties](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/elwesties/32/1909_2.png) [@elwesties](https://discuss.kotlinlang.org/u/elwesties)\
**Post date:** [April 6, 2016, 4:03pm UTC](https://discuss.kotlinlang.org/t/kotlin-string-format/1577/3 "2016-04-06T16:03:48Z")

</div>

Thank you for the help yole that works as intended now.

---

<div class="post-metadata">

**Author:** ![krmao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/krmao/32/4622_2.png) [@krmao](https://discuss.kotlinlang.org/u/krmao)\
**Post date:** [January 17, 2019, 3:39am UTC](https://discuss.kotlinlang.org/t/kotlin-string-format/1577/5 "2019-01-17T03:39:23Z")

</div>

thanks
