Wednesday, January 29, 2014

Building a String

Sometimes you want to build a string with multiple variables inserted into that string.  This is easily done with the SQL functions using the :1 :2 place holders.  You can also build them for messages with %1 place holders.  I've been looking for a way to do it in plain old peoplecode.  Here is the only solution I've come across and it uses the function MsgGetText.

Solution 1
Local String &str;
Local String &prefix = "Mr."
Local String &lName = "Jones"
&str = "Hello " | &prefix | " " | &lname | ". Welcome to Peoplecode.";

Solution 2
Local String &str;
Local String &prefix = "Mr."
Local String &lName = "Jones"
&str = MsgGetText(0, 0, "Hello %1 %2. Welcome to Peoplecode.", &prefix, &lname);

Both solutions would output in the follow format:
Hello Mr. Jones. Welcome to Peoplecode.

No comments:

Post a Comment