Tuesday, July 6, 2010

strFmtLB and the newline character (\n) in label files

You want to split your info message into multiple lines, so you use the \n newline character.
You write the following code:-
info("Line1\nLine2");
You tested it's working and the output message is split into 2 lines as below:-
Line1
Line2

Now you've converted the string into a label, so you update your code such as the one below:-
info("@WKN1");
But when you re-run the code, you realised that the newline character is no longer working and printed directly on screen. The message is displayed as one line instead of two as below:-
Line1\nLine2

To display the message correctly, you need to use the global method strFmtLB:-
info(strFmtLB("@WKN1"));
If your string message contains placeholders (%1, %2, etc.), then you can use both strFmtLB and strFmt methods together:-
info(strFmtLB(strFmt("@SYS39890", "Line1", "Line2")));
Result of running the above code:-
Line1
 Line2

1 comment: