Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
I'm trying to remove all extra spaces and hyphens. In the field there should only be allowed one space between words or one hyphen, but never both and never more than one.
I'm currently doing something like this, more it doesn't catch everything. What's a better way than this elementary way?
replace " " with "-" in gFilename
replace " " with "-" in gFilename
replace " " with "-" in gFilename
replace "--" with "-" in gFilename
replace "---" with "-" in gFilename
replace "----" with "-" in gFilename
replace "-----" with "-" in gFilename
replace "------" with "-" in gFilename
replace "-------" with "-" in gFilename
replace "--------" with "-" in gFilename
replace "---------" with "-" in gFilename
replace "----------" with "-" in gFilename
replace "-----------" with "-" in gFilename
replace "------------" with "-" in gFilename
replace "-------------" with "-" in gFilename
replace "--------------" with "-" in gFilename
replace "---------------" with "-" in gFilename
replace "----------------" with "-" in gFilename
put the length of gFileName into tLength
repeat
replace " " with " " in gFileName
if the length of gFileName = tLength then
exit repeat
end if
put the length of gFileName into tLength
end repeat
put the length of gFileName into tLength
repeat
replace "--" with "-" in gFileName
if the length of gFileName = tLength then
exit repeat
end if
put the length of gFileName into tLength
-- gFileName should be alright now
end repeat
on mouseUp
get fld 1 --field contains all those extra spaces
repeat until " " is not in it
replace " " with space in it
end repeat
put it into fld 2
end mouseUp
Same for any char. In my old handler, I cycled through a list of such recalcitrant chars:
on mouseUp
get fld 1 --field contains all those extra spaces
repeat until " " is not in it
replace " " with space in it
end repeat
repeat until "--" is not in it
replace "--" with "-" in it
end repeat
--etc.
put it into fld 2
end mouseUp
Craig
Last edited by dunbarx on Tue Sep 01, 2020 5:15 pm, edited 2 times in total.
replace " " with "-" in gFilename
replace " " with "-" in gFilename
replace " " with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
replace "-" with "-" in gFilename
I even upgraded BBEdit to have the regex playground. I am trying to get there...