Ken Getz
CIS 76137,3650

String Functions:

The .MDB file STRINGS contains 7 string functions that I have either needed or 
have heard from other Compuserve users that might be useful.  The exact details 
are outlined below.

In all actuality, the guts of the functions live in a DLL file, ASTRING.DLL.  This DLL 
must live in a directory that's in your DOS PATH in order for Access to find it.  Many
people place DLL's like these in their Windows directory.  The exact position is up 
to you.

In order to use any of the included functions (once you've placed ASTRING.DLL in your
PATH somewhere), include the module "String Routines" from the example .MDB included
here.  Once that is done, you'll be able to use these functions as if they were built-in
Microsoft Access functions.  That is, you could sort a query, for example, on 
StrRev(LastName) should you have such an interest.

One note:  since DLL's can not return strings to Access (except for variable-length strings,
the format of which is not released), these functions have to jump through some rather
silly hoops to do their work.  Because of this, you'll really not want to call the DLL
directly (as you might other DLL's), but rather, call the Access Basic functions
described below.

Please, I have only used a few of these functions more than just as examples so far.
If you have problems getting them to work correctly, please let me know so I can
fix them up.  If you have suggestions for other string functions that are general-
purpose and you think might be useful additions, please let me know.


The functions:

Function GetTokens (szStr As String, szDelimiters As String, wLimit As Integer) As Variant
Function InitCaps (szStr As String) As String
Function Proper (szStr As String) As String
Function Replace (szStr As String, szFind As String, szReplace As String) As String
Function RInstr (ByVal wStop As Integer, ByVal szSearch As String, ByVal szFind As String) As Integer
Function StrCount (ByVal szStr As String, ByVal szSearch As String) As Integer
Function StrRev (szStr As String) As String

>> GetTokens:

Function GetTokens (szStr As String, szDelimiters As String, wLimit As Integer) As Variant

Retrieve a specific, numbered token from a string, with user-specified delimiters.  For
example, you could retrieve the 3rd word from a string, by calling:

	token = GetTokens("This is a test of how this works", " ", 3)

This will place the string "a" in the variable "token".  You can specify multiple tokens,
and the function will break out tokens at any one of the listed delimiters.  That is,

	token = GetTokens("This,is,a test of,how:this works", ":, ", 4)

will return the word "test".

If wLimit is <= 0, or if you ask for a token past the end of the string, GetTokens will return
#NULL#.

Due to calling convention constraints, all strings in this function are limited to
1024 characters (though this is an arbitrary value and could be changed -- see the
Access Basic code for more information).

>> InitCaps:

Function InitCaps (szStr As String) As String

Returns the passed-in string, converted so that the first letter of each word is converted
to upper case.  Non-alphabetic characters aren't changed, and characters other than the
first in each word are not affected (see Proper() for a function that converts first letters
to uppercase and the rest to lowercase.)

	InitCaps("THIS IS A test")

returns "THIS IS A Test".

>> Proper:

Function Proper (szStr As String) As String

Returns the passed-in string, converted so that the first letter of each word is converted
to upper case, and all others to lowercase.  Non-alphabetic characters aren't changed.

	Proper("THIS IS A test")

returns "This Is A Test".

>> Replace

Function Replace (szStr As String, szFind As String, szReplace As String) As String

Search and replace one string within another, replacing it with a third.  The function
returns the changed string.

	Replace("This is a test of how this works", "is", "xx")

returns "Thxx xx a test of how thxx works".

The replacement is NOT recursive.  That is, it makes one pass and one pass only through
the passed-in string, replacing as it goes.  To make multiple different replacements,
make multiple calls to Replace().  The search used by Replace() is case-sensitive.
Due to calling convention constraints, all strings in this function are limited to
1024 characters (though this is an arbitrary value and could be changed -- see the
Access Basic code for more information).

>> RInstr

Function RInstr (ByVal wStop As Integer, ByVal szSearch As String, ByVal szFind As String) As Integer

The opposite of Instr().  That is, it starts at the end of the passed-in string, and
locates the LAST occurrence of the search string.  You can specify the LAST position
in the string you care to look for the search string.  (Specifying a position greater
than the length of the string amounts to the same thing as specifying the exact
length of the string).

	RInstr(100, "This is a test", "is")

will return 6 (the last occurrence of the string "is" starts at position 6.)

	RInstr(5, "This is a test", "is")

will return 3 (the last occurrence of the string "is" before position 5 starts at position 3.
This search is case-sensitive.

>> StrCount

Function StrCount (ByVal szStr As String, ByVal szSearch As String) As Integer

Counts the number of times szSearch occurs in szStr.  The search is CASE-SENSITIVE
(so if you DON'T care about case, convert both strings to upper or lower case before
calling StrCount()).

>> StrRev

Function StrRev (szStr As String) As String

Reverse a string and return the reversed value.

	StrRev("My name is Ken")

would return "neK si eman yM".