FlexUrlEncoder() for the forum

Share your advanced PureBasic knowledge/code with the community.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

FlexUrlEncoder() for the forum

Post by Little John »

Works also with PB 5.20

Hi all,

the forum software does not acceopt certain characters in links, which normally can be contained in URLs, e.g. http://msdn.microsoft.com/en-us/library ... S.85).aspx is not "clickable" because of the brackets.
Since brackets normally can be contained in an URL, they will not be encoded by PB's built-in URLEncoder() function. That's why I wrote the following little encoding function, which makes it easier for us to provide "clickable" links here in the forum.

Code: Select all

EnableExplicit

Procedure.s FlexUrlEncoder (url.s, charlist.s="()")
   ; charlist: List of *additionally* to encode characters
   Protected i.i, char.s

   url = URLEncoder(url)        ; Most work will be done by the built-in function.
   For i = 1 To Len(charList)
      char = Mid(charlist, i, 1)
      url = ReplaceString(url, char, "%" + Hex(Asc(char)))
   Next
   ProcedureReturn url
EndProcedure

;-- Demo
Debug     URLEncoder("http://msdn.microsoft.com/en-us/library/ms644906(VS.85).aspx")
Debug FlexUrlEnCoder("http://msdn.microsoft.com/en-us/library/ms644906(VS.85).aspx")
Are there characters other than "(" and ")", which are normally allowed in URLs but are not accepted as part of links here in the forum?

Regards, Little John
Last edited by Little John on Sun Aug 18, 2013 8:45 pm, edited 2 times in total.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Little John;

I'm not sure as i've not been able to try it yet, but I think you just solved the one problem I was having when i did the Vista Task Dialogs in this thread: http://www.purebasic.fr/english/viewtop ... taskdialog > where i talk about the url's not working correctly.

Gonna give it a go a little later, maybe your post is the solution. Thank You :)
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

2SFSxOI:
The stuff in the other thread is a bit over my head. However, I'm glad if my little idea gave you another idea. :-) I'm curious now :D, please tell me about your findings.

Regards, Little John
Post Reply