change all spaces entered into a dialog reply, into a "/ "

Hi. I’ve made an applescript which runs a shell script containing file names, and I want my AppleScript to change all occurence of spaces in “text returned of” my dialog, into "/ ". How exactly would I go about doing that?

Thank you for any help you can offer.

Lambo,

Try this. I’m sure someone else will post a much more streamlined version.

set w to ""
display dialog "a" default answer ""
set t to text returned of the result
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
repeat with i from 1 to (count text items in t)
	set w to w & text item i of t & "/"
end repeat
display dialog w
set AppleScript's text item delimiters to astid

PreTech

I don’t understand why you’re do it, but you can try something like this:

display dialog "Enter shell script:" default answer ""
set theScript to text returned of result

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set theScript to every text item of theScript

set AppleScript's text item delimiters to {"/ "}
set theScript to theScript as text
set AppleScript's text item delimiters to ASTID

return theScript

I am a fan of brevity. :slight_smile:

set theOriginalString to text returned of (display dialog "whatever here:" default answer "")
set theString to (do shell script "/bin/echo" & space & quoted form of theOriginalString & space & "| /usr/bin/sed -e 's/ /\\/ /g'")

On second glance:

Are you sure you wanted "/ " (forward slash + space), and not “/” (only a forward slash)? Just want to make sure that wasn’t a typo. If it WAS a typo, simple modification:

set theOriginalString to text returned of (display dialog "whatever here:" default answer "")
set theString to (do shell script "/bin/echo" & space & quoted form of theOriginalString & space & "| /usr/bin/sed -e 's/ /\\//g'")

Thanks for your help everyone. I greatly appreciate it :slight_smile: