Editing text contained in a variable

I need to add a space after every consonant from a variable that holds some text. I have tried many things but nothing works. I have not yet figured out a way to edit the variable that holds the text to add anything, not just spaces, after a consonant. There needs to be something like a paste command, that can just paste a space in after a consonant.

Please help!
Thanks,
Terry

AppleScript was not designed to be an English language processing tool, so expecting a simple paste command is a bit naive.

You are going to have to write a script (use a while loop) that cycle through the contents of your variable and add spaces after each character that is a consonant. You will also need to write the logic to differentiate consonants from vowels.

Shouldn’t be too hard.

yes this is what i did, i got it to figure out what was vowel and what was not, but I can’t get it to add in spaces. There is no way I can see that can do something like, set theText to space after character 2

Actually, bubba applescript was designed to be incredibly flexible, which is why it contains methods of working with strings. I’m not sure I would call it “naive” of troblong50 to hope for a command to do this easily. Other languages have simpler methods of performing this same task, which may lead someone with inexperience in AS to ‘expect’ that it might be available in this language, too. Perhaps if it’s not “too hard” to write, you could actually help the guy out with some code rather than waste all those words insulting him and not actually contribute anything.

So, yes you will need to interpret the string and repeat through it’s characters… adding any desired characters to the string as you evaluate it. Using a repeat loop is actually more practical, but the process is quite straightforward.

set theAppendChars to "*" --> The string to add after the consonants
set theQueryList to "bcdfghjklmnpqrstvwxyz"

set theInput to "The QUICK brown FOX jumped OVER the LAZY dog"
set theOutput to ""

ignoring case
	repeat with theIndex from 1 to (count theInput)
		set tmpChar to (character theIndex of theInput)
		set theOutput to (theOutput & tmpChar)
		
		if theQueryList contains tmpChar then
			set theOutput to (theOutput & theAppendChars)
		end if
	end repeat
end ignoring

return theOutput --> The new string with the chars added

Hope this is what you’re looking for.
j

Yes! that is exactly what I was looking for! Thank you so much!

No kidding - AppleScript’s built-in text processing facilities are appallingly poor, waaaay behind what you’d expect from any vaguely decent modern scripting language.

Fortunately, there are some third-party tools available that go a little way towards compensating for this, e.g. the [a href=http://www.satimage.fr/software/en/scripting_additions.html]Satimage osax[/a] includes basic regular expression support that provides a far faster, single-line solution:

set theInput to "The QUICK brown FOX jumped OVER the LAZY dog"
set theOutput to change "([bcdfghjklmnpqrstvwxyz])" into "\1 " in theInput regexpflag {"EXTENDED", "NEWLINE", "ICASE"} with regexp
--> "T h e Q UIC K  b r ow n  F OX  j um p ed  OV ER  t h e L AZ Y  d og "