Page 1 of 1
Find & Replace with Wildcard(s)
Posted: Wed Jan 22, 2025 4:20 pm
by richmond62
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 . . .
Re: Find & Replace with Wildcard(s)
Posted: Wed Jan 22, 2025 5:25 pm
by richmond62
Well: no answers forthcoming.
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
Really fairly tedious.
Re: Find & Replace with Wildcard(s)
Posted: Wed Jan 22, 2025 5:47 pm
by richmond62
This did NOT do what it was supposed to do:
-
-
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)
Posted: Wed Jan 22, 2025 6:24 pm
by Klaus
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
Re: Find & Replace with Wildcard(s)
Posted: Wed Jan 22, 2025 6:46 pm
by richmond62
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
-

- 42961.png (12.26 KiB) Viewed 8574 times
-
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)
Posted: Wed Jan 22, 2025 7:39 pm
by dunbarx
Richmond.
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
Craig
Re: Find & Replace with Wildcard(s)
Posted: Wed Jan 22, 2025 8:01 pm
by dunbarx
Or if there are more images of other types with other types of names:
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
That sort of thing...
Craig
Re: Find & Replace with Wildcard(s)
Posted: Wed Jan 22, 2025 8:17 pm
by richmond62
Wouldn't it have been easier to cycle through all the .png names and:
It probably would, but I was in a hurry, no-one was holding my hand, and my mentality is stuck in about 1984.
