Find & Replace with Wildcard(s)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Livecode Opensource Backer
- Posts: 10080
- Joined: Fri Feb 19, 2010 10:17 am
Find & Replace with Wildcard(s)
I have a large number of images-as-buttons that have a naming convention that goes like this: 118.png, and they are referred to in a cardScript like that.
Now those images-as-buttons look pretty shabby, so I have replaced them with less shabby images-as-buttons with a naming convention like this: b118.
Because I am a fairly lazy sort and do not want to go through a monster Switch statement line by name changing all the instances of 'XXX.png' (and that 'XXX' may vary from 2 to 6 characters) to 'bXXX', I wonder if there is a way to use the Find & Replace stack to do that automatically . . .
Now those images-as-buttons look pretty shabby, so I have replaced them with less shabby images-as-buttons with a naming convention like this: b118.
Because I am a fairly lazy sort and do not want to go through a monster Switch statement line by name changing all the instances of 'XXX.png' (and that 'XXX' may vary from 2 to 6 characters) to 'bXXX', I wonder if there is a way to use the Find & Replace stack to do that automatically . . .
-
- Livecode Opensource Backer
- Posts: 10080
- Joined: Fri Feb 19, 2010 10:17 am
Re: Find & Replace with Wildcard(s)
Well: no answers forthcoming.
While waiting, I didn't wait and did this instead in a button:
Really fairly tedious.
While waiting, I didn't wait and did this instead in a button:
Code: Select all
on mouseup
put the script of this card into fld "SKRIPT"
put 1 into VOX
repeat until word VOX of fld "SKRIPT" is empty
if word VOX of fld "SKRIPT" contains ".png" then
put word VOX of fld "SKRIPT" into VOXXX
put VOXXX into fld "VOCKS"
delete the second char of fld "VOCKS"
put "b" after the first char of fld "VOCKS"
delete char -2 of fld "VOCKS"
delete char -2 of fld "VOCKS"
delete char -2 of fld "VOCKS"
delete char -2 of fld "VOCKS"
put fld "VOCKS" into VOKS
put (" " & VOKS) after word VOX in fld "SKRIPT"
delete word VOX of fld "SKRIPT"
end if
add 1 to VOX
end repeat
set the script of this card to fld "SKRIPT"
end mouseup
-
- Livecode Opensource Backer
- Posts: 10080
- Joined: Fri Feb 19, 2010 10:17 am
Re: Find & Replace with Wildcard(s)
This did NOT do what it was supposed to do:
- -
So I modified the script:
- -
So I modified the script:
Code: Select all
on mouseup
put the script of this card into fld "SKRIPT"
put 1 into VOX
repeat until word VOX of fld "SKRIPT" is empty
if word VOX of fld "SKRIPT" contains ".png" then
put word VOX of fld "SKRIPT" into VOXXX
put VOXXX into fld "VOCKS"
delete the first char of fld "VOCKS"
put (quote & "b") before fld "VOCKS"
delete char -2 of fld "VOCKS"
delete char -2 of fld "VOCKS"
delete char -2 of fld "VOCKS"
delete char -2 of fld "VOCKS"
put fld "VOCKS" into VOKS
put (" " & VOKS) after word VOX in fld "SKRIPT"
delete word VOX of fld "SKRIPT"
end if
add 1 to VOX
end repeat
set the script of this card to fld "SKRIPT"
end mouseup
Re: Find & Replace with Wildcard(s)
Hi Richmond,
can you please show us how the imagenames are stored in your script?
And how are they "managed", sequential or random numbers?
Important hint:
Put the content of a field into a variable first, work with that variable and you will experience a HEAVY speed bump!
Accessing fields is "expensive", especially in a loop.
Best
Klaus
can you please show us how the imagenames are stored in your script?
And how are they "managed", sequential or random numbers?
Important hint:
Put the content of a field into a variable first, work with that variable and you will experience a HEAVY speed bump!

Accessing fields is "expensive", especially in a loop.
Best
Klaus
-
- Livecode Opensource Backer
- Posts: 10080
- Joined: Fri Feb 19, 2010 10:17 am
Re: Find & Replace with Wildcard(s)
The HEAVY speed bump was not important as it was a 'once off'.
The images are apparently fairly random: here's a selection of them:
257.png
240.png
42961.png
- -
and their names in the cardScript have to be changed to the following:
b257
b240
b42961
as they have been replaced with images-as-buttons with those names.
BUT as I have already achieved that with the script I have posted above, my question is largely redundant.
The images are apparently fairly random: here's a selection of them:
257.png
240.png
42961.png
- -
and their names in the cardScript have to be changed to the following:
b257
b240
b42961
as they have been replaced with images-as-buttons with those names.
BUT as I have already achieved that with the script I have posted above, my question is largely redundant.
Re: Find & Replace with Wildcard(s)
Richmond.
Wouldn't it have been easier to cycle through all the .png names and:
Craig
Wouldn't it have been easier to cycle through all the .png names and:
Code: Select all
set the itemDel to "png"
repeat with y = 1 to the number of imgages
set the name of image y to "b" & item 1 of the short name of image y
end repeat
Re: Find & Replace with Wildcard(s)
Or if there are more images of other types with other types of names:
That sort of thing...
Craig
Code: Select all
set the itemDel to "png"
repeat with y = 1 to the number of imgs
if item 1 of the short name of img y is an integer then set the name of img y to "b" & item 1 of the short name of img y
end repeat
Craig
-
- Livecode Opensource Backer
- Posts: 10080
- Joined: Fri Feb 19, 2010 10:17 am
Re: Find & Replace with Wildcard(s)
It probably would, but I was in a hurry, no-one was holding my hand, and my mentality is stuck in about 1984.Wouldn't it have been easier to cycle through all the .png names and:
