home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
dbase
/
duflp
/
strings.prg
< prev
next >
Wrap
Text File
|
1992-06-25
|
29KB
|
778 lines
*-------------------------------------------------------------------------------
*-- Program...: STRINGS.PRG
*-- Programmer: Ken Mayer (KENMAYER)
*-- Date......: 06/25/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: REAME.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.......: None
*-- Called by...: Any
*-- Usage.......: CutPaste(<cFld>,"<cLookFor>","<cRepWith>")
*-- Example.....: Replace all city with CutPaste(City,"L.A.","Los Angeles")
*-- Returns.....: The field with text replaced (or not, if no match is found)
*-- Parameters..: cFld = Field/Memvar/Expression to replace in
*-- cLookFor = Item to look for (Cut)
*-- cRepWith = What to replace it with (Paste)
*-------------------------------------------------------------------------------
parameters cFld,cLookFor,cRepWith
private lMatched,nLookLen,nLen,nRepLen,cRetFld,nTrimLen,nCutAt
*-- Make sure they're all character fields/strings
if type("cFld")+type("cLookFor")+type("cRepWith") # "CCC"
RETURN cFld
endif
lMatched = .f.
nLookLen = len(cLookFor) && length of field to look for
nLen = len(cFld) && length of original field
nRepLen = len(cRepWith) && length of field to replace with
cRetFld = trim(cFld) && trim it ... (DCREEK's suggestion)
*-- the loop will allow a cut/paste to occur more than once in the field
do while at(cLookFor,cRetFld) > 0
lMatched = .t.
cRetFld = trim(cRetFld)
nTrimLen = len(cRetFld)
*-- the following IF statement prevents the replacement text
*-- from overflowing the length of the original string ...
if(nTrimLen - nLookLen) + nRepLen > nLen
RETURN cRetFld
endif
*-- here we figure where to "cut" at
nCutAt = at(cLookFor,cRetFld)
*-- let's do the paste ... (using dBASE STUFF() function)
cRetFld = stuff(cRetFld,nCutAt,nLookLen,cRepWith)
enddo
if .not. lMatched && no match with cLookFor, return original field
RETURN cFld
endif
RETURN cRetFld
*-- EoF: CutPaste
FUNCTION LastWord
*-------------------------------------------------------------------------------
*-- Programmer..: Martin Leon (HMAN)
*-- Date........: 12/19/1991
*-- Notes.......: Returns the last word in a character string.
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: LastWord("<cString>")
*-- Example.....: ? LastWord("This is a test string")
*-- Returns.....: The Last word (bracketed with spaces), i.e.:"string"
*-- Parameters..: cString = string to be searched
*-------------------------------------------------------------------------------
parameters cString
private cReturn
cReturn = trim(cString)
do while at(" ",cReturn) # 0
cReturn = substr(cReturn,at(" ",cReturn)+1)
enddo
RETURN cReturn
*-- EoF: LastWord()
FUNCTION VStretch
*-------------------------------------------------------------------------------
*-- Programmer...: Martin Leon (HMAN -- Ashton Tate/Borland BBS)
*-- Date.........: 10/30/91
*-- Notes........: Used to display a long character field, with proper word wrap
*-- Written for..: dBASE IV, 1.1
*-- Rev. History.: Once upon a time, Martin helped me write a more complicated
*-- routine for use in a browse table. He came up with this
*-- much less complex version recently and sent to me via EMail.
*-- Calls........: None
*-- Called by....: Any
*-- Usage........: ?VStretch(<cLFld>,<nULRow>,<nULCol>,<nBRRow>,<nBRCol>)
*-- Example......: ?VStretch(Notes,20,10,24,60,"rg+/gb")
*-- Returns......: "" (Nul)
*-- Parameters...: cLFld = Long Field to be wrapped on screen
*-- nULRow = Upper Left Row of window
*-- nULCol = Upper Left Column
*-- nBRRow = Bottom Right Row of window
*-- nBRCol = Bottom Right Column
*-------------------------------------------------------------------------------
parameter cLFld,nULRow,nULCol,nBRRow,nBRCol
private nWinWidth
nWinWidth = ltrim(str((nBRCol - nULCol)-1,2))
*-- define window without any border ...
define window wStretch from nULRow,nULCol to nBRRow,nBRCol none
activate window wStretch
*-- make sure window is empty ...
clear
*-- display field
?? cLFld picture "@V"+nWinWidth at 0 && the @V function causes word wrap
save screen to sTemp
activate screen
release window wStretch
restore screen from sTemp
release screen sTemp
RETURN ""
*-- EoF: VStretch()
FUNCTION AtCount
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: returns the number of times FindString is found in Bigstring
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: AtCount("<cFindStr>","<cBigStr>")
*-- Example.....: ? AtCount("Test","This is a Test string, with Test data")
*-- Returns.....: Numeric value
*-- Parameters..: cFindStr = string to find in cBigStr
*-- cBigStr = string to look in
*-------------------------------------------------------------------------------
parameters cFindstr, cBigstr
private cTarget, nCount
cTarget = cBigstr
nCount = 0
do while .t.
if at( cFindStr,cTarget ) > 0
nCount = nCount + 1
cTarget = substr( cTarget, at( cFindstr, cTarget ) + 1 )
else
exit
endif
enddo
RETURN nCount
*-- EoF: AtCount()
FUNCTION IsAlNum
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Returns .T. if the first character of cChar is alphanumeric,
*-- otherwise it is false.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: IsAlNum("<cChar>")
*-- Example.....: ? IsAlNum("Test")
*-- Returns.....: Logical
*-- Parameters..: cChar = character string to check for Alphanumeric ...
*-------------------------------------------------------------------------------
parameters cChar
RETURN isalpha( cChar ) .or. left( cChar, 1 ) $ "0123456789"
*-- EoF: IsAlNum()
FUNCTION IsAscii
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Returns .t. if the first character of cChar is in the lower
*-- half of the ASCII set ( value < 128 )
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: IsAscii("<cChar>")
*-- Example.....: ? IsAscii("Teststring")
*-- Returns.....: Logical
*-- Parameters..: cChar = string to test
*-------------------------------------------------------------------------------
parameters cChar
RETURN asc( cChar ) < 128
*-- EoF: IsAscii()
FUNCTION IsCntrl
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Returns .t. if the first character of cChar is a delete,
*-- or a control character.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: IsCntrl("<cChar>")
*-- Example.....: ? IsCntrl("Test")
*-- Returns.....: Logical
*-- Parameters..: cChar = string to test
*-------------------------------------------------------------------------------
parameters cChar
private nCharval
nCharval = asc(cChar)
RETURN nCharval = 127 .or. nCharval < 32
*-- EoF: IsCntrl()
FUNCTION IsDigit
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: If the first character of cChar is a digit, returns .T.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: IsDigit("<cChar>")
*-- Example.....: ? IsDigit("123Test")
*-- Returns.....: Logical
*-- Parameters..: cChar = string to test
*-------------------------------------------------------------------------------
parameters cChar
RETURN left( cChar, 1 ) $ "0123456789"
*-- EoF: IsDigit()
FUNCTION IsPrint
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Returns .t. if first character of cChar is a printing
*-- character (space through chr(126) ).
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: IsPrint("<cChar>")
*-- Example.....: ? IsPrint("Test")
*-- Returns.....: Logical
*-- Parameters..: cChar = string to test
*-------------------------------------------------------------------------------
parameters cChar
private nCharval
nCharval = asc(cChar)
RETURN nCharval > 31 .and. nCharval < 127
*-- EoF: IsPrint()
FUNCTION IsXDigit
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Returns .t. if first character of cChar is a possible
*-- hexidecimal digit.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: IsXDigit("<cChar>")
*-- Example.....: ? IsXDigit("F000")
*-- Returns.....: Logical
*-- Parameters..: cChar = string to test
*-------------------------------------------------------------------------------
parameters cChar
RETURN left( cChar, 1 ) $ "0123456789ABCDEFabcdef"
*-- EoF: IsXDigit()
FUNCTION IsSpace
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Returns .T. if first character of cChar is in set of space,
*-- tab, carriage return, line feed, vertical tab or formfeed,
*-- otherwise .F. Differs from C function of the same
*-- name in treating chr(141), used as carriage return
*-- in dBASE memo fields, as a space.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: IsSpace("<cChar>")
*-- Example.....: ? IsSpace(" Test")
*-- Returns.....: Logical
*-- Parameters..: cChar = string to test
*-------------------------------------------------------------------------------
parameters cChar
private cSpacestr
cSpacestr = " "+chr(9)+chr(10)+chr(11)+chr(12)+chr(13)+chr(141)
RETURN left( cChar, 1 ) $ cSpacestr
*-- EoF: IsSpace()
FUNCTION Name2Label
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Returns a name held in five separate fields or memvars as it
*-- should appear on a label of a given length in characters.
*-- The order of abbreviating is somewhat arbitrary--you may
*-- prefer to remove the suffix before the prefix, or to remove
*-- both before abbreviating the first name. This can be
*-- accomplished by rearranging the CASE statements, which operate
*-- in the order of their appearance.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: Name2Label(<nLength>,"<cPrefix>","<cFirstName>",;
*-- "<cMidName>","<cLastName>","<cSuffix>")
*-- Example.....: ? Name2Label(20,"The Rev.","Elmore","Norbert","Smedley","III")
*-- Returns.....: Character String, in this case "E. N. Smedley, III"
*-- Parameters..: nLength = length of label
*-- cPrefix = Prefix to name, such as Mr., Ms., Dr...
*-- cFirstName = self explanatory
*-- cMiddleName = self explanatory
*-- cLastName = self explanatory
*-- cSuffix = "Jr.", "M.D.", "PhD", etc.
*-------------------------------------------------------------------------------
parameters nLength, cPrefix, cFirstname, cMidname, cLastname, cSuffix
private cTrypref, cTryfirst, cTrymid, cTrylast, cTrysuff, cTryname
cTrypref = ltrim( trim( cPrefix ) )
cTryfirst = ltrim( trim( cFirstname ) )
cTrymid = ltrim( trim( cMidname ) )
cTrylast = ltrim( trim( cLastname ) )
cTrysuff = ltrim( trim( cSuffix ) )
do while .t.
cTryname = cTrylast
if "" # cTrymid
cTryname = cTrymid + " " + cTryname
endif
if "" # cTryfirst
cTryname = cTryfirst + " " + cTryname
endif
if "" # cTrypref
cTryname = cTrypref + " " + cTryname
endif
if "" # cTrysuff
cTryname = cTryname + ", " + cTrysuff
endif
if len(cTryname) <= nLength
exit
endif
do case
case "" # cTrymid .AND. right( cTrymid, 1 ) # "."
cTrymid = left( cTrymid, 1 ) + "." && convert middle name to initial
case "" # cTryfirst .AND. right( cTryfirst, 1 ) # "."
cTryfirst = left( cTryfirst, 1 ) + "." && convert first name to initial
case "" # cTrypref
cTrypref = "" && drop prefix
case "" # cTrysuff
cTrysuff = "" && drop suffix
case "" # cTrymid
cTrymid = "" && drop middle initial
case "" # cTryfirst
cTryfirst = "" && drop first initial
otherwise
cTrylast = left( cTrylast, nLength ) && truncate last name
endcase
enddo
RETURN cTryName
*-- EoF: Name2Label()
FUNCTION StrPBrk
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Search string for first occurrence of any of the
*-- characters in charset. Returns its position as
*-- with at(). Contrary to ANSI.C definition, returns
*-- 0 if none of characters is found.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: StrPBrk("<cCharSet>","<cBigStr>")
*-- Example.....: ? StrPBrk("Tt","This is a Test string, with Test data")
*-- Returns.....: Numeric value
*-- Parameters..: cCharSet = characters to look for in cBigStr
*-- cBigStr = string to look in
*-------------------------------------------------------------------------------
parameters cCharset, cBigstring
private nPos, nLooklen
nPos = 0
nLooklen = len( cBigstring )
do while nPos < nLooklen
nPos = nPos + 1
if at( substr( cBigstring, nPos, 1 ), cCharset ) > 0
exit
endif
enddo
RETURN iif(nPos=nLookLen,0,nPos)
*-- EoF: StrPBrk()
FUNCTION Rat
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Reverse "at", returns position a character string is last
*-- AT in a larger string.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: Rat("<cFindStr>","<cBigStr>")
*-- Example.....: ? Rat("Test","This is a Test string, with Test data")
*-- Returns.....: Numeric value
*-- Parameters..: cFindStr = string to find in cBigStr
*-- cBigStr = string to look in
*-------------------------------------------------------------------------------
parameters cFindstr, cBigstr
private nPos,nLen
nLen = len( cFindstr )
nPos = len( cBigstr ) - nLen + 1
do while nPos > 0
if substr( cBigstr, nPos, nLen ) = cFindstr
exit
else
nPos = nPos - 1
endif
enddo
RETURN max( nPos, 0 )
*-- EoF: RAt()
FUNCTION StrRev
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Reverses a string of characters, returns that reversed string.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: StrRev("<cAnyStr>")
*-- Example.....: ? StrRev("This is a Test")
*-- Returns.....: Character string
*-- Parameters..: cAnyStr = String of characters to reverse ...
*-------------------------------------------------------------------------------
parameters cAnystr
private cRevstring, nX,nY
nX = len( cAnystr )
nY = 1
cRevstring = space( nX )
do while nX > 0
cRevstring = stuff(cRevstring,nY,1,substr(cAnyStr,nX,1))
nY = nY + 1
nX = nX - 1
enddo
RETURN cRevstring
*-- EoF: StrRev()
FUNCTION Strip2Val
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Strip characters from the left of a string until reaching
*-- one that might start a number.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: Strip2Val("<cStr>")
*-- Example.....: ? Strip2Val("Test345")
*-- Returns.....: character string
*-- Parameters..: cStr = string to search
*-------------------------------------------------------------------------------
parameters cStr
private cNew
cNew = cStr
do while "" # cNew
if left( cNew, 1 ) $ "-.0123456789"
exit
endif
cNew = substr( cNew, 2 )
enddo
RETURN cNew
*-- EoF: Strip2Val()
FUNCTION StripVal
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 03/01/92
*-- Notes.......: Strip characters from the left of the string until
*-- reaching one that is not part of a number. A hyphen
*-- following numerics, or a second period,
*-- is treated as not part of a number.
*-- Written for.: dBASE IV
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: StripVal("<cStr>")
*-- Example.....: ? StripVal("123.2Test")
*-- Returns.....: Character
*-- Parameters..: cStr = string to test
*-------------------------------------------------------------------------------
parameters cStr
private cNew, cChar, lGotminus, lGotdot
cNew = cStr
store .f. to lGotminus, lGotdot
do while "" # cNew
cChar = left( cNew, 1 )
do case
case .not. cChar $ "-.0123456789"
exit
case cChar = "-"
if lGotminus
exit
endif
case cChar = "."
if lGotdot
exit
else
lGotdot = .T.
endif
endcase
cNew = substr( cNew, 2 )
lGotminus = .T.
enddo
RETURN cNew
*-- EoF: StripVal()
FUNCTION ParseWord
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (Jparsons).
*-- Date........: 04/26/1992
*-- Notes.......: returns the first word of a string
*-- Written for.: dBASE IV, 1.1, 1.5
*-- Rev. History: None
*-- Calls : None
*-- Called by...: Any
*-- Usage.......: ? ParseWord(<cString>)
*-- Example.....: Command = ParseWord( cProgramline )
*-- Parameters..: cString - character string to be stripped.
*-- Returns : that portion, trimmed on both ends, of the passed string
*-- that includes the characters up to the first interior space.
*-------------------------------------------------------------------------------
parameters string
private cW
cW = trim( ltrim( string ) )
RETURN iif( " " $ cW, rtrim( left( cW, at( " ", cW ) - 1 ) ), cW )
*-- EoF: ParseWord()
FUNCTION StripWord
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (Jparsons).
*-- Date........: 04/26/1992
*-- Notes.......: discards first word of a string
*-- Written for.: dBASE IV, 1.1, 1.5
*-- Rev. History: None
*-- Calls : None
*-- Called by...: Any
*-- Usage.......: ? StripWord(<cString>)
*-- Example.....: Lastname = StripWord( "Carrie Nation" )
*-- Parameters..: cString - character string to be stripped.
*-- Returns : string trimmed of trailing spaces, and trimmed on the
*-- left to remove leading spaces and, if the passed string
*-- contained interior spaces, also to remove everything before
*-- the first nonspace character after the first interior space.
*-------------------------------------------------------------------------------
parameters string
private cW
cW = trim( ltrim( string ) )
RETURN iif( " " $ cW, ltrim( substr( cW, at( " ", cW ) + 1 ) ), cW )
*-- EoF: StripWord()
*-------------------------------------------------------------------------------
*-- EoP: STRINGS.PRG
*-------------------------------------------------------------------------------