WebDaily: Your daily source for Web Technology Tips and Tricks! -Forward this email and subscription information to a fellow developer!********************************************************************** More VBScript-to-JavaScript Functions*********************************************************************** This article provides code for a number of VBScript-to-JavaScriptconvertions.Here are some more useful VBScript-to-JavaScript functions:Len(String) : Returns the number of characters in a string=========================================================== function Len(str) /*** IN: str - the string whose length we are interested in RETVAL: The number of characters in the string ***/ { return String(str).length; }Left(string, length): Returns a specified number of characters from the left side of a string======================================================================== function Left(str, n) /*** IN: str - the string we are LEFTing n - the number of characters we want to return RETVAL: n characters from the left side of the string ***/ { if (n <= 0) // Invalid bound, return blank string return ""; else if (n > String(str).length) // Invalid bound, return return str; // entire string else // Valid bound, return appropriate substring return String(str).substring(0,n); }Right(string, length): Returns a specified number of characters from the right side of a string======================================================================== function Right(str, n) /*** IN: str - the string we are RIGHTing n - the number of characters we want to return RETVAL: n characters from the right side of the string ***/ { if (n <= 0) // Invalid bound, return blank string return ""; else if (n > String(str).length) // Invalid bound, return return str; // entire string else { // Valid bound, return appropriate substring var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } }Mid(string, start, length): Returns a specified number of characters from a string============================================================================ function Mid(str, start, len) /*** IN: str - the string we are LEFTing start - our string's starting position (0 based!!) len - how many characters from start we want to get RETVAL: The substring from start to start+len ***/ { // Make sure start and len are within proper bounds if (start < 0 || len < 0) return ""; var iEnd, iLen = String(str).length; if (start + len > iLen) iEnd = iLen; else iEnd = start + len; return String(str).substring(start,iEnd); }// Keep in mind that strings in JavaScript are zero-based, so if you ask// for Mid("Hello",1,1), you will get "e", not "H". To get "H", you would// simply type in Mid("Hello",0,1)// You can alter the above function so that the string is one-based. Just// check to make sure start is not <= 0, alter the iEnd = start + len to// iEnd = (start - 1) + len, and in your final return statement, just// return ...substring(start-1,iEnd)I am starting a repository of VBScript-to-JavaScript functions. If you'dlike to browse the current function list, look no further thanhttp://www.4GuysFromRolla.com/webtech/vb2java.shtmlHappy Programming!****************************************************************************************************************************************** To subscribe to WebDaily, point your browser to: http://www.4GuysFromRolla.com/webtech/webdaily To unsubscribe from WebDaily, reply to this email with the following subject: UNSUBSCRIBE WEBDAILY******************************************************************************************************************************************Thank you for subscribing to WebDaily!If you know someone who could benefit from a wealth of web developmenttechnology, invite them to visit http://www.4GuysFromRolla.com/new
Source Code
|