home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best Objectech Shareware Selections
/
UNTITLED.iso
/
boss
/
data
/
dbas
/
004
/
strings.prg
< prev
next >
Wrap
Text File
|
1992-08-31
|
44KB
|
1,214 lines
*-------------------------------------------------------------------------------
*-- Program...: STRINGS.PRG
*-- Programmer: Ken Mayer (KENMAYER)
*-- Date......: 08/31/1992
*-- Notes.....: String manipulation routines -- These routines are all designed
*-- to handle the processing of "Strings" (Character Strings).
*-- They range from simple checking of the location of a string
*-- inside another, to reversing the contents of a string ...
*-- and lots more. See the file: README.TXT for details on use
*-- of this (and the other) library file(s).
*-------------------------------------------------------------------------------
FUNCTION Proper
*-------------------------------------------------------------------------------
*-- Programmer..: Clinton L. Warren (VBCES)
*-- Date........: 07/10/1991
*-- Notes.......: Returns cBaseStr converted to proper case. Converts
*-- "Mc", "Mac", and "'s" as special cases. Inspired by
*-- A-T's CCB Proper function. cBaseStr isn't modified.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: 07/10/1991 1.0 - Original version (VBCES/CLW)
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: Proper(<cBaseStr>)
*-- Example.....: Proper("mcdonald's") returns "McDonald's"
*-- Returns.....: Propertized string (e.g. "Test String")
*-- Parameters..: cBaseStr = String to be propertized
*-------------------------------------------------------------------------------
PARAMETERS cBaseStr
private nPos, cDeli, cWrkStr
cWrkStr = lower(cBaseStr) + ' ' && space necessary for 's process
nPos = at('mc', cWrkStr) && "Mc" handling
do while nPos # 0
cWrkStr = stuff(cWrkStr, nPos, 3, upper(substr(cWrkStr, nPos, 1)) ;
+ lower(substr(cWrkStr, nPos + 1, 1)) ;
+ upper(substr(cWrkStr, nPos + 2, 1)))
nPos = at('mc', cWrkStr)
enddo
nPos = at('mac', cWrkStr) && "Mac" handling
do while nPos # 0
cWrkStr = stuff(cWrkStr, nPos, 4, upper(substr(cWrkStr, nPos, 1)) ;
+ lower(substr(cWrkStr, nPos + 1, 2)) ;
+ upper(substr(cWrkStr, nPos + 3, 1)))
nPos = at('mac', cWrkStr)
enddo
cWrkStr = stuff(cWrkStr, 1, 1, upper(substr(cWrkStr, 1, 1)))
nPos = 2
cDeli = [ -.'"\/`] && standard delimiters
do while nPos <= len(cWrkStr) && 'routine' processing
if substr(cWrkStr,nPos-1,1) $ cDeli
cWrkStr = stuff(cWrkStr, nPos, 1, upper(substr(cWrkStr,nPos,1)))
endif
nPos = nPos + 1
enddo
nPos = at("'S ", cWrkStr) && 's processing
do while nPos # 0
cWrkStr = stuff(cWrkStr, nPos, 2, lower(substr(cWrkStr, nPos, 2)))
nPos = at('mac', cWrkStr)
enddo
RETURN (cWrkStr)
*-- EoF: Proper()
FUNCTION Justify
*-------------------------------------------------------------------------------
*-- Programmer..: Roland Bouchereau (Ashton-Tate)
*-- Date........: 12/17/1991
*-- Notes.......: Used to pad a field/string on the right, left or both,
*-- justifying or centering it within the length specified.
*-- If the length of the string passed is greater than
*-- the size needed, the function will truncate it.
*-- Taken from Technotes, June 1990. Defaults to Left Justify
*-- if invalid TYPE is passed ...
*-- Written for.: dBASE IV, 1.0
*-- Rev. History: Original function 06/15/1991/
*-- 12/17/1991 -- Modified into ONE function from three by
*-- Ken Mayer, added a third parameter to handle that.
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: Justify(<cFld>,<nLength>,"<cType>")
*-- Example.....: ?? Justify(Address,25,"R")
*-- Returns.....: Padded/truncated field
*-- Parameters..: cFld = Field/Memvar/Character String to justify
*-- nLength = Width to justify within
*-- cType = Type of justification: L=Left, C=Center,R=Right
*-------------------------------------------------------------------------------
parameters cFld,nLength,cType
private cReturn
cType = upper(cType) && just making sure ...
if type("cFld")+type("nLength")+type("cType") $ "CNC,CFC"
*-- set a picture function of 'X's, with @I,@J or @B function
cReturn = transform(cFld,iif(cType="C","@I ",iif(cType="R","@J ","@B "));
+replicate("X",max(0,min(nLength,254))))
else
cReturn = ""
endif
RETURN cReturn
*-- EoF: Justify()
FUNCTION Dots
*-------------------------------------------------------------------------------
*-- Programmer..: Ken Mayer (KENMAYER)
*-- Date........: 12/17/1991
*-- Notes.......: Based on ideas from Technotes, June, 1990 (see JUSTIFY() ),
*-- this function should pad a field or memvar with dots to the
*-- left, right or both sides. Note that if the field is too
*-- large for the length passed (nLength) it will be truncated.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: None
*-- Calls.......: ALLTRIM() Function in PROC.PRG
*-- Called by...: Any
*-- Usage.......: Dots(<cFld>,<nLength>,"<cType>")
*-- Example.....: ?? Dots(Address,25,"R")
*-- Returns.....: Field/memvar with dot leader/trailer ...
*-- Parameters..: cFld = Field/Memvar/Character String to justify
*-- nLength = Width to justify within
*-- cType = Type of justification: L=Left, C=Center,R=Right
*-------------------------------------------------------------------------------
parameters cFld,nLength,cType
private cReturn, nVal, nMore
if type("cFld")+type("nLength")+type("cType") $ "CNC,CFC"
cType = upper(cType) && just to make sure ...
cReturn = AllTrim(cFld) && trim this puppy on all sides
if len(cReturn) => nLength && check length against parameter
&& truncate if necessary
cReturn = substr(cReturn,1,nLength)
endif
do case
case cType = "L" && Left -- add trailing dots to field
cReturn = cReturn + replicate(".",nLength-len(cReturn))
case cType = "R" && Right -- add leading dots to field
cReturn = replicate(".",nLength-len(cReturn))+cReturn
case cType = "C" && Center -- add 'em to both sides ...
nVal = int( (nLength - len(cReturn)) / 2)
*-- here, we have to deal with fractions ...
nMore = mod(nlength - len(cReturn), 2)
*-- add dots on left, field, dots on right (add one if a fraction)
cReturn = replicate(".",nVal)+cReturn+;
replicate(".",nVal+iif(nMore>0,1,0))
otherwise && invalid parameter ... return nothing
cReturn = ""
endcase
else
cReturn = ""
endif
RETURN cReturn
*-- EoF: Dots()
FUNCTION CutPaste
*-------------------------------------------------------------------------------
*-- Programmer..: Martin Leon (HMAN)
*-- Date........: 03/05/1992
*-- Notes.......: Used to do a cut and paste within a field/character string.
*-- (Taken from an issue of Technotes, can't remember which)
*-- This function will not allow you to overflow the field/char
*-- string -- i.e., if the Paste part of the function would cause
*-- the returned field to be longer than it started out, it will
*-- not perform the cut/paste (STUFF()). For example, if your
*-- field were 15 characters, and you wanted to replace 5 of them
*-- with a 10 character string:
*-- (CutPaste(field,"12345","1234567890"))
*-- If this would cause the field returned to be longer than 15,
*-- the function will return the original field.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: Original function 12/17/1991
*-- 03/05/1992 -- minor change to TRIM(cFLD) in the early
*-- bits, solving a minor problem with phone numbers that
*-- Dave Creek (DCREEK) discovered.
*-- Calls.......: N