web stats
Mirth Community - View Single Post - Mirth Tools: User defined functions
View Single Post
  #3  
Old 04-17-2012, 10:43 AM
upstart33 upstart33 is offline
Mirth Guru
 
Join Date: Dec 2010
Location: Chicago, IL.
Posts: 459
upstart33 is on a distinguished road
Default

3. Misc. Trim functions
Purpose: Sometimes, you need to do some trimming of strings. If you do not feeling like memorizing Regex, you can use something along the lines of the following.

Code:
function trim(in_str) {
    return new String(in_str).replace(/^\s+|\s+$/g,"");
}
Code:
function ltrim(in_str) {
    return new String(in_str).replace(/^\s+/,"");
}
Code:
function rtrim(in_str) {
    return new String(in_str).replace(/\s+$/,"");
}

Now, the function can be called within a transformer or mapper step:
Code:
var fname= trim(msg['patient_first'].toString());
Reply With Quote