/*JS String/Number/Array Functions Script Library Last Updated : 9th July 2008 List of functions in this library - ---------------------------------- STRING Functions ---------------------------------- AtWord - @Word equivalent strLeft - @Left equivalent strRight - @Right equivalent rightBack - @RightBack equivalent leftBack - @LeftBack equivalent middle - @Middle equivalent ConvertReturnToBR - Converts carriage returns to
for display in HTML replaceSubstring - @ReplaceSubstring equivalent LTrim - Lotusscript LTrim equivalent RTrim - Lotusscript LTrim equivalent Trim - @Trim equivalent ( Note the uppercase T in Trim ) trim - @Trim equivalent (another version) ( Note the lowercase t in trim) IsMemberStr - @IsMember equivalent ---------------------------------- NUMBER Functions --------------------------------- IsNumeric IsAlphaNumeric ---------------------------------- ARRAY Functions ----------------------------------- PopulateListArr - puts the items in the array to the dialog list field which is passed IsMemberArr MakeUniqueArr - makes an array unique RemNullArr - removes all the null values in the array */ //------------------------------- STRING Functions ---------------------------------------------------------------------------------- //@Word equivalent function AtWord(StringtoSplit , Seperator , number) { var arr = StringtoSplit.split(Seperator); return(arr[number-1]); } //@Left equivalent function strLeft(sourceStr, keyStr){ return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : sourceStr.split(keyStr)[0]; } //@Right equivalent function strRight(sourceStr, keyStr){ idx = sourceStr.indexOf(keyStr); return (idx == -1 | keyStr=='') ? '' : sourceStr.substr(idx+ keyStr.length); } //@RightBack equivalent function rightBack(sourceStr, keyStr){ arr = sourceStr.split(keyStr); return (sourceStr.indexOf(keyStr) == -1 | keyStr=='') ? '' : arr.pop() } //@LeftBack equivalent function leftBack(sourceStr, keyStr){ arr = sourceStr.split(keyStr) arr.pop(); return (keyStr==null | keyStr=='') ? '' : arr.join(keyStr) } //@Middle equivalent function middle(sourceStr, keyStrLeft, keyStrRight){ return strLeft(strRight(sourceStr,keyStrLeft), keyStrRight); } // Converts carriage returns to
for display in HTML function ConvertReturnToBR(input) { var output = ""; for (var i = 0; i < input.length; i++) { if ((input.charCodeAt(i) == 13) && (input.charCodeAt(i + 1) == 10)) { i++; output += "
"; } else { output += input.charAt(i); } } return output; } //@ReplaceSubstring equivalent function replaceSubstring(Inputstr,from,to) { var pos,I,pos1,temp,len; var lfrom=from.length; while(Inputstr.indexOf(from)>=0) { pos=Inputstr.indexOf(from) temp=Inputstr.substring(0,pos)+ to+Inputstr.substring(pos+lfrom) Inputstr=temp } return Inputstr } //replaceSubstring // Removes leading whitespaces function LTrim( value ) { var re = /\s*((\S+\s*)*)/; return value.replace(re, "$1"); } // Removes ending whitespaces function RTrim( value ) { var re = /((\s*\S+)*)\s*/; return value.replace(re, "$1"); } // Removes leading and ending whitespaces function Trim( value ) { return LTrim(RTrim(value)); } // Removes leading and ending whitespaces function trim(sStr) { var iI = 0; var iJ = 0; var iTam = 0; var sAux = ""; iTam = sStr.length; if(iTam==0) return(sStr); for(iI=0; iI= iTam) return(""); for(iJ=iTam - 1; iJ>=0; iJ--) if(sStr.charAt(iJ)!=' ') break; return(sStr.substring(iI,iJ+1)); } //End of trim function IsMemberStr(Str,StrToSearch) { if(Str.indexOf(StrToSearch)>=0) return true; else return false; } //------------------------------- NUMBER Functions ---------------------------------------------------------------------------------- function IsNumeric(sText) { var ValidChars = "0123456789."; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } function IsAlphaNumeric(val) { if (val.match(/^[a-zA-Z0-9]+$/)) { return true; } else { return false; } } //------------------------------- ARRAY Functions ---------------------------------------------------------------------------------- //puts the items in the array to the dialog list field which is passed // arr is an array and field is the dialog list object name which is to be populated function PopulateListArr(arr, field) { field.options.length=arr.length; for(j=0;j