changing some elements of a filename

Hi
I’m newish to AS and I can find out how to do the following
Remove all instances of an underscore from a filename unless its the first character
I can do all the instances

set AppleScript's text item delimiters to "_"
	set theItemList to every text item in mystring
	set AppleScript's text item delimiters to ""
	set the Newstring to every item in theItemList as string

but I cant find out how to leave the first item unchanged if it is an underscore

Help would be appreciated

-warren


tell application "Finder"

	set myFile to choose file

	set myFilename to name of myFile

	if (myFilename's character 1 = "_") then

		set myFilename to "_" & my SwapTextItems(myFilename, "_", "")
	else
		set myFilename to my SwapTextItems(myFilename, "_", "")

	end if

	set name of myFile to myFilename

end tell

on SwapTextItems(str, sub, rep)
	set tids to AppleScript's text item delimiters
	set AppleScript's text item delimiters to sub
	set str to str's text items
	set AppleScript's text item delimiters to rep
	set str to str as string
	set AppleScript's text item delimiters to tids
	return str
end SwapTextItems

This would be a slightly different way to go:


...
	if (myFilename's character 1 = "_") then

		set myFilename to text 2 thru -1 of myFilename

		set preChar to "_"
	else
		set preChar to ""
		
	end if

	set myFilename to preChar & my SwapTextItems(myFilename, "_", "")
...

Thank you the second version works a treat

-warren