General Interface is an open source project hosted by the Dojo Foundation

Get the Right X characters of a string

Get the right X characters from the string value passed. The code is setup to be included in a package titled "utils", change the package name on the declaration line to add it to any other package.

right
/**
 * Return the right number of characters specified in noChars from the string passed.
 * @param strValue {String} text to have right segment extracted
 * @param noChars - int - number of chars from the right to be extracted
 */
utils.right = function(strValue, noChars)
{
  try
  {
    if (noChars <= 0)
      return "";
    else if (noChars > String(strValue).length)
      return strValue;
    else 
    {
      var iLen = String(strValue).length;
      return String(strValue).substring(iLen, iLen - noChars);
    }
  } 
  catch (e) 
  {
    e = jsx3.NativeError.wrap(e);
    jsx3.log("util.right error: " + e.getMessage());
  }
}

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.