AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=158&pId=-1
Useful JavaScript/VBScript String Functions (Server side)
page
by Taewook Kang
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 33433/ 53

VBScript Version

Following are the common string functions (both in VBScript and JavaScript) which can be used in your application.

<SCRIPT LANGUAGE="VBScript" RUNAT=Server>

'chop function
'Author: Taewook Kang ( txkang@wichita.edu )

'
'chop function takes four arguments.
'Ex:
'if you do...
'chop( "Hello Kang! Nice to meet you!","",leftPortion,rightPortion )
'as a result, leftPortion will contain "Hello Kang! Nice" and rightPortion will
contain " to meet you!" 'I find this function useful in making newsletter application
and I use this often.

function chop( byval s,byval item,byref p1,byref p2 )
     dim chop_itemLength,chop_location

     chop_itemLength = len( item )
     chop_location = instr( 1,s,item,vbBinaryCompare )

     p1 = mid( s,1,chop_location - 1 )
     p2 = mid( s,chop_location + chop_itemLength,len( s ) )
end function

</script>
JavaScript Version

 

<SCRIPT LANGUAGE="JavaScript" RUNAT=Server>

/*
firStr function
Author: Taewook Kang ( txkang@wichita.edu )
Ex:
if you do...
fitStr( "Hello Kang! Nice to meet you!",5,10 )
it will return
Hello... you!

This function is very useful when you need to print long URLs.
*/

function fitStr( u,sideLength,offset )
{
     if ( u )
     {
          var curLen = u.length;
          return ( curLen >= offset ) ? u.substr( 0,sideLength ) + "..." + u.substr( curLen - sideLength,curLen ) : u;
     }      else
          return null;
}

/*
superTrim function
Author: Taewook Kang ( txkang@wichita.edu )

Ultimate trim function. It will trim all invisible
characters ( \n,\t.. etc ) before and after a string.
*/

function superTrim( s )
{
     return ( s ) ? s.replace( /^[\n\t\r ]+/,'' ).replace( /[\n\t\r ]+$/,'' ) : null;
}
</SCRIPT>

 


Product Spotlight
Product Spotlight 

©Copyright 1998-2017 ASPAlliance.com  |  Page Processed at 2017-07-23 8:55:41 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search