Hi everyone
I have a problem - I want to take a certain string, for example “Blinky_Bill” and replace the “_” with a space.
So that I will get “Blinky Bill”.
I have been reading up on text item delimiters, but I’m afraid that I don’t understand them in relation to this problem, it seems that they only replace text items in an artificial list, not characters in a string.
Does anyone have a solution to this? any input would be greatly appreciated
Try something like this:
set example to "Blinky_Bill"
set example to replaceText("_", " ", example)
-- find : Text to be found
-- replace : Text to replace with
-- subject : Text to be searched
on replaceText(find, replace, subject)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to find
set subject to text items of subject
set AppleScript's text item delimiters to replace
set subject to "" & subject
set AppleScript's text item delimiters to prevTIDs
return subject
end replaceText
Getting the text items
of a string returns a list which is created by splitting (exploding, etc.) the string at every occurrence of AppleScript’s text item delimiters. Coercing a list to a string joins (i.e. concatenates) all of the list items, with AppleScript’s text item delimiters being inserted between each item.
See also:
http://bbs.applescript.net/viewtopic.php?id=18551
http://bbs.applescript.net/viewtopic.php?id=11449
http://bbs.applescript.net/viewtopic.php?id=13008