Conversion between open location and Safari URL strings

I am attempting to reconcile a URL string accepted by the command open location with the URL string returned by Safari’s URL string. The check mark character “✓” accepted by the open location does not match the %E2%9C%93 returned by Safari’s URL string.

set TargetURL to "✓"
tell application "Safari"
	open location TargetURL
	tell current tab of window 1
		set SafariURL to its URL -->""
	end tell
end tell
if SafariURL is TargetURL then
	return true
	return false
end if

How can I convert open location’s URL to Safari’s URL by converting the check mark character “✓” to %E2%9C%93 or vice versa, without using Applescript’s text items delimiters to substitute one for the other?

Code posting tags corrected by NG.

This is known as URL encoding <–> decoding. The most effective way I know, is using AsObjC:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

-- vise
set encodedTargetURL to my encodeURLencoding("✓")

-- versa (uncomment following code line to test)
-- set decodedTargetURL to my decodeURLencoding(encodedTargetURL)

on encodeURLencoding(origStr as string)
	set aStr to current application's NSString's stringWithString:origStr
	set encodedStr to aStr's stringByAddingPercentEscapesUsingEncoding:(current application's NSUTF8StringEncoding)
	return encodedStr as string
end encodeURLencoding

on decodeURLencoding(encodedStr)
	set aStr to current application's NSString's stringWithString:encodedStr
	set bStr to aStr's stringByReplacingPercentEscapesUsingEncoding:(current application's NSUTF8StringEncoding)
	return bStr as string
end decodeURLencoding

KniazidisR, the simplicity of your script is great! Thank you so much for your help.