Below is a generic Search and Replace routine that I have been using
for years. It allows for any length string using the "contains"and
"offset" commands. I believe that this is faster than going
character by character.
But the real question is why do you have "hard coded" path names in
your program? You can build your paths to be cross platform
compatible by using "the last char of the moviePath" as your
separator.
Anyway, here's the routine:
on SearchAndReplace input, stringToFind, stringToInsert, bOnlyOnce
if voidp(bOnlyOnce) then
bOnlyOnce = FALSE -- defaults to replacing all
end if
output = ""
findLen = length( stringToFind ) - 1
if bOnlyOnce then
currOffset = offset( stringToFind, input )
if currOffset = 0 then
return input -- no occurances
end if
output = output & char 1 to currOffset of input
delete the last char of output
output = output & stringToInsert
delete char 1 to ( currOffset + findLen ) of input
else -- all
repeat while input contains stringToFind
currOffset = offset( stringToFind, input )
output = output & char 1 to currOffset of input
delete the last char of output
output = output & stringToInsert
delete char 1 to ( currOffset + findLen ) of input
end repeat
end if
set output = output & input
return output
end
Irv
At 5:28 PM +0200 5/23/05, arjen wrote:
hi
this must be so easy, but i can't find the answer anywhere;
howto replace all occurences of a character in a string with another
character?
the time i wasted with searching i could have also spent with making
a handler that does that,
but there must be a much faster way of doing it than looping through
all chracters in the string,
test to see if it needs to be replaced?
actually i'm looking for a way to convert mac or pc paths into
unix-style paths,
so instead of "HD:Users:pietje .." i want "/Users/pietje/.."
is there maybe a function to do that?
arri
[To remove yourself from this list, or to change to digest mode, go
to http://www.penworks.com/lingo-l.cgi To post messages to the
list, email lingo-l@penworks.com (Problems, email
[EMAIL PROTECTED]). Lingo-L is for learning and helping with
programming Lingo. Thanks!]
--
Multimedia Wrangler.
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
lingo-l@penworks.com (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]