Stripping unwanted chars from URL

I have an appscript that takes user input, puts it together with a saved user preference and other coded bits to get a proper URL, for example

but because of what some users might enter (even when instructed not to :slight_smile: the result can end up as

–>How do I strip out unnecessary “//” without killing the necessary one?

set badURL to ""

set AppleScript's text item delimiters to "//"
set badURL to badURL's text items
set AppleScript's text item delimiters to "/"
set goodURL to badURL's item 1 & "//" & rest of badURL as string
set AppleScript's text item delimiters to {""}


TIDs are our friends! :lol:

Works perfect. I’ve put off learning this kind of code as I’ve always found text and string handling overly cryptic (don’t even talk about regexp). This, however, is clever enough it makes sense to me. Thanks again.


If there’s one thing to learn about handling text that you shouldn’t put off, it’s this (using text item delimiters). It’s one of the most powerful and overlooked tools available to scripters. :slight_smile:

Allow me to interject: here here!

Give it up for text item delimiters! wOOt!