FP: looking for Field function 
Author Message
 FP: looking for Field function

I'm looking for a function that will return a string in a comma delimited
string. So if I have a string "one,two,three" and I say GetField(s,',',1) it
should return "one" (the first string separated by commas).

I found one called Piece but it doesn't work with FreePascal, it is in
assembler.

Thanks.
Chuck

--
Freezone Freeware and Free delphi Components
http://www.*-*-*.com/ http://www.*-*-*.com/
http://www.*-*-*.com/



Tue, 27 Dec 2005 23:48:17 GMT  
 FP: looking for Field function
Found a working field function called Parse. Put these 2 functions in a unit.

{*****************************************************************************
 * Function ...... ParseCount()
 * Purpose ....... To count the number of tokens in a string
 * Parameters .... cString      String to count tokens in
 *                 cChar        Token separator
 * Returns ....... Number of tokens in <cString>
 * Notes ......... Uses function StripChar
 * Author ........ Martin Richardson
 * Date .......... September 30, 1992
 *****************************************************************************}
FUNCTION ParseCount( cString: STRING; cChar: CHAR ): INTEGER;
BEGIN
     ParseCount := LENGTH(cString) - LENGTH(StripChar(cString, cChar)) + 1;
END;

{*****************************************************************************
 * Function ...... Parse()
 * Purpose ....... To parse out tokens from a string
 * Parameters .... cString      String to parse
 *                 nIndex       Token number to return
 *                 cChar        Token separator
 * Returns ....... Token <nIndex> extracted from <cString>
 * Notes ......... If <nIndex> is greater than the number of tokens in
 *                 <cString> then a null string is returned.
 *               . Uses function Left, Right, and ParseCount
 * Author ........ Martin Richardson
 * Date .......... September 30, 1992
 *****************************************************************************}
FUNCTION Parse( cString:STRING; cChar:CHAR; nIndex:INTEGER ): STRING;
VAR
   i: INTEGER;
   cResult: STRING;
BEGIN
     IF nIndex > ParseCount( cString, cChar ) THEN
        cResult := ''
     ELSE BEGIN
          cString := cString + cChar;
          FOR i := 1 TO nIndex DO BEGIN
              cResult := Left( cString, POS( cChar, cString ) - 1 );
              cString := Right(cString, LENGTH(cString) - POS(cChar, cString));
          END { Next I };
     END { IF };
     Parse := cResult;
END; {parse}

--
Freezone Freeware and Free Delphi Components
http://freezone.darksoft.co.nz http://chuckr.bravepages.com
http://www.bdsg.com/resources



Mon, 02 Jan 2006 00:41:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. power function: looking to improve this one.

2. looking for function to capture a keypress

3. I am looking for a RANDOM function...

4. I am looking for a RANDOM function...

5. Question: (FPC): is the FP.EXE in de WIN32 different than the FP.EXE in the GO32V2 dir?

6. Procedure for Looking Up Calculated Fields

7. Looking for DEC Pascal field test sites

8. Can FP or VFP handle chinese characters

9. Newbie, FP installation problem

10. Url for ide called FP

11. TP to FP port

12. NEW VERSIONS: GraphiX for Pascal (GX/BP v7.20, GX/FP: v1.00.alpha6)

 

 
Powered by phpBB® Forum Software