|
Post by SunBurnt on Oct 19, 2011 3:12:06 GMT 1
I modified James Fuller`s ExtractStr function so it acts like "cut".
I changed a few variable names in the process, and renamed it STR_CUT. I like the idea of all the "Str..." files in one place, and all the "List..." files, etc., etc.
I may add more string functions to it, if I find the need for them.
What do I need to do to get it posted at the BaCon site in: User contributed functions? I left James Fuller`s remarks at the top and added the changes to them. Should Mr. Fuller be notified?
I think all these String functions should eventually be in one file ( STR_EDIT ).
Thanks for all the help... Terry B.
REM REM Contributed by James C. Fuller - April 2009. REM REM' bacon ExtractStr REM REM REM Modified and renamed by Terry Becker - Oct. 18 2011 REM REM It now acts like the Linux command "cut" REM REM File name and function "ExtractStr" have been renamed to STR_CUT REM Main$ is renamed to Str$ REM REM Returns empty string if "Col" is out of bounds ( too large )
FUNCTION STR_CUT(STRING Str$, STRING Delim$, int Col) LOCAL i TYPE int LOCAL St TYPE int LOCAL End TYPE int ' LOCAL sRet$ TYPE STRING ' sRet$ = ""
REM T.B. Modified this IF statement. IF (LEN(Str$) EQ 0) OR (LEN(Delim$) EQ 0) THEN RETURN ""
REM T.B. Added everything below. SPLIT Str$ BY Delim$ TO A$ SIZE aSize IF Col > aSize THEN RETURN "" RETURN A$[Col - 1] ENDFUNCTION
'### Tests below if this file is compiled. ' RET$ = STR_CUT("James C. Fuller", " ", 2) ' RET$ = STR_CUT("Terry,M.,Becker", ",", 1) ' RET$ = STR_CUT("Terry,M.,Becker", ",", 4) PRINT RET$
|
|
|
Post by GatorDog on Oct 19, 2011 5:33:30 GMT 1
Hi sunburnt,
I didn't run the code yet, but is this what it is doing?Ret$ = REPLACE$("1234567890", "456", "") rod
|
|
|
Post by SunBurnt on Oct 19, 2011 7:08:24 GMT 1
Didn`t notice there was a command for it, so why the ReplaceStr function? Oh well... ### I submitted a different function above.
|
|