Whether you are integrating enterprise systems over different transports, messaging conventions, adding mediation logic to existing services or writing some code for your pet IoT project you will be dealing with a lot of string manipulations. Now, string manipulation is not something a programmer needs to learn repeatedly, but since Ballerina is a whole new beast of a programming language(in the making) it might be advisable to invest a bit of time to get familiar with the its string manipulation capabilities.
Ballerina provides a bunch of string utility methods somewhat similar to python, packed under ballerina.lang.strings. Look to the Strings API documentation[1] for a complete list of methods. Apart from these utility methods, Ballerina supports escaping(“\””) and concatenation(+) same as Java and provide inline formatting capabilities such as “\t” for tab and “\n” for newline.
The code segment found below shows how some of the methods discussed above can be used in a real world scenario where a header value passed into a ballerina service and depending on the callers time a response is generated and sent out.
Try out the ballerina script above with these invocations,
[1] - http://ballerinalang.org/docs/api/0.8/ballerina.lang.strings.html
Note: this example was written for ballerina 0.86 and it may not work with other versions.
Great Article
ReplyDeleteInternet of Things Final Year Project
Final Year Project Centers in Chennai