String Manipulation Extensions

Introduction

This example shows how to use the stringutil.lua module that contains a library of helpful extensions to the standard Lua string library. It also allows equivalent functions to be called directly on HL7, XML etc. ‘node trees’ which reduces the need to cast these to a string using the :S() method.

If you have any questions please contact us at support@interfaceware.com.

Tip: From Iguana 6.0.3 much of this functionality has been natively implemented in the core of Iguana so there is less need for stringutil after this. This version of stringutil checks for builtin implementations of these functions, and if they exist leaves the builtin implementations in place.

Using the Code [top]

  • Import the String Manipulation Extensions channel from the Builtin: Iguana Tools repository
  • Experiment with the code to find out how it works
  • Then add the module to your Translator project
  • Copy the require statement from the channel and add it at the top of your script
    Note: This module modifies the global namespace
  • Adapt the code to your own requirements
  • Use the various string utility functions as required:
    • trimRWS() – trim white space from the right
    • trimLWS() – trim white space from the left
    • trimWS() – trim white space from both sides
    • compactWS() – replace multiple spaces with a single space
  • Interactive scripting help is included for this module

This is the github code for the main module:

How it works [top]

The four functions that remove white space use string matching to remove spaces. The capitalize() function uppercases the first letter in the string, and lowercases the remaining letters.

More information [top]

Tagged:

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.