Trim leading or Trailing Spaces in Siebel eScript

 

Scenario

 As there is no library function available for trimming leading or trailing characters (like spaces) in Siebel eScript, one need to create a custom function. Following options can be used:

  • Traditional approach – Using While/Recursion
  • Optimized approach – Using Regular Expressions

One can easily design the function with while/recursion, so I won’t discuss that. I will start with the Second approach.

 

Approach 2 : Using Reg Expr

As Siebel escript supports Regular expressions, I will show you how to trim the characters using them:

  • RTrimSpaces (OrgStr) – This function will remove the trailing spaces from the passed string.

function RTrimSpaces (OrgStr)
{
 var Pattern = /\s*$/; //Regular Expression
 var TrimStr = OrgStr.replace(Pattern,””); //Replace with blank
    
 return(TrimStr);
}

  • LTrimSpaces (OrgStr) – This function will remove the leading spaces.

function LTrimSpaces (OrgStr)
{
 var Pattern = /^\s*/; //Regular Expression
 var TrimStr = OrgStr.replace(Pattern,””); //Replace with blank
    
 return(TrimStr);

 

Understanding Reg Expr Used

 Let me explain you elements of the Regular Expressions used in above functions:

  • ‘/’ – Marks the start and end of a pattern
  • ‘\s’ – Matches the whitespace characters like space, tab, new line
  • ‘^’ – Instruct to search at the begining of the string
  • ‘$’ – Instruct to search at the end of the string
  • ‘*’ – Instruct to find zero or more instances

I have used Reg Expr in a specific scenario. But if you want to play around with it, please refer to http://gskinner.com/RegExr/ for additional information. 

Happy Scipting. 🙂

2 responses to this post.

  1. yeah nice

    Reply

  2. […] this excellent post by Suansh Singhal on his crackingsiebel.com blog – a really useful BS for trimming leading (LTrim) and trailing […]

    Reply

Appreciate your feedback

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: