TextManip.Asp is a set of text manipulation functions that I found lacking in VB(a/s) moving from a Perl/PHP background. I hope to continue to add to these functions as time permits and the need arises. Note that the TMJoin(), TMSplit(), and TMReplace() functions have all been supersceeded thanks to Microsoft's infanite wisdom in adding these gems to the core language (Version 5.0 of Microsoft® Visual Basic® Scripting Engine). Personally I feel these should have been implemented from the start, along with several other language features that have long existed in such server side languages as Perl and PHP. I highly recommend the use of PHP in place of ASP whenever possible. I also encourage the use of Perl when the amount of code significantly outweighs the amount of HTML. I will turn these functions into wrappers for the built in functions once the 5.0 scripting engine is out of beta. I will also have the code check for the scripting engine version number and use the built in version if possible to ensure backward compatability.

You may download the full zip archive of this file and the .asp include file in one convinient package. I hope you find it useful. If you have questions, suggestions, bugs, bug fixes, or enhancements please send them to pdavis(at)pobox.com so that they may be wrapped into future versions of TextManip.


Here are a few examples of how to use TextManip.asp functions. The original string that we will start with will be ":!This:!is:!a:!TextManip:!Example:!Go:!88:!:!", without the quotes. The separator is the characters ":!"

TMSplit(): Here we call the TMSplit() function to split the string up into an array. We call TMSplit(":!", sString, 0, aString) where ":!" is the sparator, sString is the text to split, 0 is the number to limit on, and aString will be the array that is modified. In the limiting factor, 0 represents no limit.

NumToText(): Converts numbers to a format you might see in a check writing program. We call NumToText(aString(7)) and substitute any numbers for number strings. This would mostly be used in check writing. 88 becomes Eighty eight and 0/100

TMJoin(): We then send this array to the TMJoin() function like with TMJoin("-", aString) and put it back together with the separator defined as a dash and the array defined in aString: -This-is-a-TextManip-Example-Go-Eighty eight and 0/100--

TMReplace(): Now we will call TMReplace() and substiture the dash for a space. This is done with TMReplace("-", " ", sString, TRUE, TRUE) where the dash is what we are replacing, the space is what we are replacing the dash with, sString is the string to do the replacement on, the third TRUE represents case sensitivity on (TRUE) or off (False) and the last true represents a global search and replace on (TRUE) or off (FALSE). If global search and replace is turned off then only the first occurence will be changed: This is a TextManip Example Go Eighty eight and 0/100

WordWrap(): This function converts raw text into CRLF delimited lines. We call WordWrap(sString, 10) function and split up the sentence (sString) into no more than 10 characters per line:

This is a 
TextManip 
Example Go 
Eighty 
eight and 
0/100

Initials(): This function can take a string of any length and return the first letter of each word concatanated with or without periods. To demonstrate we set our sString to a name, say "Frank James" and then "Frank Jessee James" and call it with Initials(sString, FALSE) and Initials(sString, TRUE) respectivly. The TRUE bolean value tells the function to include periods in the return value. frank james becomes FJ and Frank J. James becomes F.J.J.

Chop(): Chops off the last character of a string and returns the character chopped. It's used primarily to remove the newline from the end of an input record r
FooBa

Chomp(): This is a slightly safer version of chop. It is called with Chomp(pRef, sEnding) Where pRef is a string or array of strings to be manipulated. It removes any line ending that corresponds to the sEnding paramater. It returns the total number of characters removed from all its arguments. It's often used to remove the newline from the end of an input record when you're worried that the final record may be missing its newline. If you chomp a list, each element is chomped, and the total number of characters removed is returned.

UC(): This is called with UC(EXPR) and returns EXPR in all uppercase. This is currently no more than a wrapper for the VB function UCase() but makes porting scripts from other languages a little easier. I may add the ability to accept an array in the future.

UCFirst(): Called with UCFirst(EXPR). Returns the value of EXPR with the first character uppercased. It does not change the case of any of the other characters in the string.


Back to Phil's homepage.