Useful string functions in JavaScript to InDesign and Web


Removes leading and terminating spaces

function trim (str) 
{
  return str.replace (/^\s+/, '').replace (/\s+$/, '');
}

Check, whether a string is empty, e.g. also finds. “            elseif ”

function isBlank(str) 
{
    return str.replace(/\s/g,"") == ""  ;
}

Checked, if a string contains e.g.. whether script in javascript contained – true.

function stringContains(str, needle )
{
    return str.indexOf(needle) != -1    
}