RosettaCodeData/Task/URL-encoding/Yabasic/url-encoding.basic

18 lines
502 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
sub encode_url$(s$, exclusions$, spaceplus)
local res$, i, ch$
2026-04-30 12:34:36 -04:00
2023-07-01 11:58:00 -04:00
for i=1 to len(s$)
ch$ = mid$(s$, i, 1)
if ch$ = " " and spaceplus then
ch$ = "+"
elsif not instr(esclusions$, ch$) and (ch$ < "0" or (ch$ > "9" and ch$ < "A") or (ch$ > "Z" and ch$ < "a") or ch$ > "z") then
res$ = res$ + "%"
ch$ = upper$(hex$(asc(ch$)))
end if
res$ = res$ + ch$
next i
return res$
end sub
print encode_url$("http://foo bar/")