[futurebasic] change suffix routine for ken's rosetta stone functions

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2001 : Group Archive : Group : All Groups

From: jonathan <jonnnathan@...>
Date: Sun, 11 Nov 2001 13:02:34 +0100
for lochness i needed, for the export functions, to change the suffix on a
file [.html -> .txt, for example], and so developed this sort function:
'---- start ---
clear local mode
local fn changeSuffix$( theFileName as str255, theSuffix as str255)
dim returnStr as str255
dim cntr      as int
'
returnStr[0] = 0
long if( theFileName[0])
cntr = theFileName[0]
do
long if( theFileName[cntr] =_".")
returnStr = left$( theFileName,cntr -1) +"." +theSuffix
exit fn
end if
cntr -= 1
until( cntr <= 1)
end if
returnStr = theFileName +"." +theSuffix
end fn = returnStr
'---- end ---
as usual, i am sure that someone elese will reduce this to two lines, but it
also occurred to me that another could be needed, in preparation for 'x'.

it is common in unix systems to see names like 'toto.html.bak', or
'httpd.conf.bak'; in this case it would be useful to have a function that
targeted a certain block of letters and changed them to another:
'toto.html.bak' -> 'toto.txt'
or
'httpd.conf.bak' -> 'httpd.conf'

in this case the function should take three params:
theFileName as str255 ['x' allows long file names]
theTarget   as str15  [the chunk to seek, ie, .html, or .conf]
theSuffix   as str15  [what the target should be replaced by...]

this function, should then work back from the end of theFileName until it
finds theTarget, then replace that to the end of theFileName with theSuffix.
thus, in my examples:

theFileName = toto.html.bak
theTarget   = html
theSuffix   = txt
result      -> toto.txt

theFileName = httpd.conf.bak
theTarget   = conf
theSuffix   = conf
result      -> httpd.conf

that's all for today,
:-j