liveBook · Manning

String function

As explained in Julia as a Second Language

The string function converts values, including numbers, into their textual string representation and can combine multiple arguments.

Use `string()` when numbers, Booleans, and text need to become one `String`. It accepts multiple arguments, converts non-strings to text, and joins the results without printing them. section 5.1.2

julia> string("abc", 42, true, "xyz")
"abc42truexyz"

The mixed arguments become the single value `"abc42truexyz"`. By contrast, `print` displays those characters instead of returning the assembled string. section 5.1.2

Build a message with a number

With `engine = "RD-180"` and `thrust = 3830`, `string(engine, " produces ", thrust, " kN of thrust")` returns `"RD-180 produces 3830 kN of thrust"`. There is no need to convert `thrust` separately. section 11.2.3

For other ways to assemble text, use `*` to concatenate strings or `$` to interpolate values inside a string literal. `string()` is useful when the pieces are already separate arguments. section 11.2.3

How Julia as a Second Language covers it

How deep it goes
Demonstrates conversion and multiple arguments through REPL calls, then compares alternatives without detailing conversion internals.
Examples
Uses mixed text, number, and Boolean arguments, plus a rocket-engine description containing numeric thrust.
What it assumes
Assumes basic familiarity with values and function calls; introduces the distinction between returning a String and printing text.
What you can do after
Apply it via Julia's `string()` to convert numbers and assemble mixed-type text without printing it.
How it connects
Connects string conversion to print, println, string concatenation, and string interpolation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.