Split strings using a delimiter
Verified
Added by iNTERFACEWARE
Use the string.split() function to split a string into parts separated by a specified delimiter
Source Code
-- split the message into individual lines "\r" separator local r = msg:split('\\r') trace(r) -- allow for the \n added because we split the msg declaration over multiple lines (above) local r = msg:split('\\r\n') trace(r) -- split the message into fields "|" separator local r = msg:split('|') trace(r)
Description
Use the string.split() function to split a string into parts separated by a specified delimiter
Usage Details
Use string.split()
to break a string into multiple parts using a specified separator. We used an HL7 message as an example. When we declared the string the editor added newlines (\n) so our first split contained \n at the start of the split strings (which we did not want). Our second split allows for this by specifying the newline as part of the separator.
How to use the snippet:
- Paste the split code into your script
Note: You may also be interested in the splitText() function which can be use to split a long reports into chunks of a specified length.
Added by iNTERFACEWARE
Use conn:execute() to update a database table
Added by iNTERFACEWARE
Use os.fs.chmod() to set file permissions, using octal mode (symbolic mode does not work)
Added by iNTERFACEWARE
Use node.child() to return the node of the specified name, works for all node types
Added by iNTERFACEWARE
How to create and unzip a bzip2 or gzip file, using filter.bzip2.deflate() and filter.bzip2.inflate() or gzip.deflate() and gzip.inflate()
Added by iNTERFACEWARE
Use the error() function to raise an error and write it to the logs
Added by iNTERFACEWARE
Use conn:merge{} to merge data into a database
Added by iNTERFACEWARE
Use os.remove() to delete a file or directory, only an empty directory can be deleted
Added by iNTERFACEWARE
Use node.childCount() to count the number of children for a specified node, works for all node types
Added by iNTERFACEWARE
How to encode and decode strings with hex, using filter.hex.enc() and filter.hex.dec()
Added by iNTERFACEWARE
How to create Error, Warning, Informational, and Debug log entries
Added by iNTERFACEWARE
Use iguana.isTest() to prevent code from running in the editor
Added by iNTERFACEWARE
Use os.fs.rmdir() to delete an empty directory, if the directory is not empty an error is returned
Added by iNTERFACEWARE
Use node.isKey() to check if a node is the primary key for a database table, this method only for table node trees
Added by iNTERFACEWARE
How to encode strings with html special characters, using filter.html.enc()
Added by iNTERFACEWARE
How to open and read a file from disk, either one line at a time, or read the whole file at once
Added by iNTERFACEWARE
Use iguana.isTest() to allow code to run in the editor but not in the live channel
Added by iNTERFACEWARE
Use node.isLeaf() to check if a node is a leaf node (has no children), works for all node types
Added by iNTERFACEWARE
Encode and decode strings for use in uri/url, using filter.uri.enc() and filter.uri.dec()
Added by iNTERFACEWARE
How to convert numbers and node trees to a to string representation, and how to convert a numeric strings to numbers