2

How can we have a new line within the string backtick template?

For example the new line is not appearing in string backtick template of the following code.

import ballerina/io;
public function main() {
    string s1 = string`This is first line \n This is second line`; //New line is not appearing
    string s2 = "This is first line \nThis is second line"; //New line is appearing
    io:println(s1);
    io:println(s2);
}
Anupama Pathirage
  • 631
  • 2
  • 10
  • 22

1 Answers1

1

We need to interpolate the new line character into it to get it working. Sample code is as follows.

import ballerina/io;
public function main() {
    string s1 = string`This is first line ${"\n"}This is second line`; //New line is interpolated
    io:println(s1);
}
Anupama Pathirage
  • 631
  • 2
  • 10
  • 22