Is it possible to format strings in xtend? I am looking for something just like sprintf in C.
I tried using the String.format in java but I don't know why it is not available in xtend. Maybe, they have something similar?
Is it possible to format strings in xtend? I am looking for something just like sprintf in C.
I tried using the String.format in java but I don't know why it is not available in xtend. Maybe, they have something similar?
You can create nicely formatted strings (including line breaks, etc.) using the XPand language inline in XText, thus:
val myVar = 'Hello, world!'
println('''This is a string referring to a variable: «myVar».
It will print out «myVar?.length ?: 0» characters, as the
variable «IF myVar == null»is«ELSE»is not«ENDIF» null.''')
If you need access to Java's String.format
function, remember that static members are access using a double-colon, thus:
val formatted = String::format("Value: %1$.2f", 3.142)