changing a space to an underscore

I need to be able to change a space into an underscore. The name of the files may varry and some may not have any spaces. Any help would be appericated.

My script makes a folder then names it below is the portion that names it. I just need to be able to change any spaces that the user enters into a underscore.

“Enter the Job Name:“default answer”” buttons{“Cancel”, “Ok”} default button 2 with icon 1)}

Try something like this:

display dialog "Enter the Job Name:" default answer "" with icon 1
set jobName to simpleReplace(" ", "_", text returned of result)


on simpleReplace(search, replace, subject)
	set ASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to search
	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 ASTID
	
	return subject
end simpleReplace

See also: str_replace()