Convertir une chaîne pour utilisation dans une URL...

Convertir une chaîne pour utilisation dans une URL...

Messagepar thierry.ceretto » 30 Mars 2006 à 10:29

Source forum Notes

The best way to handle these characters is to convert them to their HTML entities before passing them in the
Query String.

Alternatively you could convert them to HEX and then back to ASCII, but that requires a conversion both ways. This
is the best I could come up with. It works well. The extra "&" used by the HTML entity should not get in the way of
any parsing since the characters are converted before the query string is read by Notes agent.

In the case of "http://server/path/TestFrenchChars?OpenAgent&téléphone"

QueryString$ = doc.Query_String(0)
' QueryString$ will be equal to "OpenAgent&téléphone" (no extra ampersands, é has been removed)

Bad Example:
http://server/path/TestFrenchChars?OpenAgent&téléphone

Good Example:
http://server/path/TestFrenchChars?Open ... cute;phone

________________________
Below is a sub-routine you can use to do the conversion before creating the QueryString. This is for FRENCH
characters only.
________________________
Function ConvertFrench(Instring As String) As String

NewString$ = ""
For i = 1 To Len(Instring)

NextChar$ = Mid$(Instring, i, 1)

If Instr({'´??éÉèÈêÊàÀâÂáÁçÇîÎíÍìÌôÔóÓòÒúÚûÛùÙ} , NextChar$) = 0 Then
REM the "Select Case" will slow it down. Don't do a check unless it is one of the 32 characters or 4 quotes listed
NewString$ = NewString$ & NextChar$
Elseif Instr({'´??} , NextChar$) > 0 Then
REM convert the different types of quotes
NewString$ = NewString$ & "?"
Else
Select Case NextChar$
Case "é"
NewString$ = NewString$ & "é"
Case "É"
NewString$ = NewString$ & "É"
Case "è"
NewString$ = NewString$ & "è"
Case "È"
NewString$ = NewString$ & "È"
Case "ê"
NewString$ = NewString$ & "ê"
Case "Ê"
NewString$ = NewString$ & "Ê"
Case "à"
NewString$ = NewString$ & "à"
Case "À"
NewString$ = NewString$ & "À"
Case "â"
NewString$ = NewString$ & "â"
Case "Â"
NewString$ = NewString$ & "Â"
Case "á"
NewString$ = NewString$ & "á"
Case "Á"
NewString$ = NewString$ & "Á"
Case "ç"
NewString$ = NewString$ & "ç"
Case "Ç"
NewString$ = NewString$ & "Ç"
Case "î"
NewString$ = NewString$ & "î"
Case "Î"
NewString$ = NewString$ & "Î"
Case "í"
NewString$ = NewString$ & "í"
Case "Í"
NewString$ = NewString$ & "Í"
Case "ì"
NewString$ = NewString$ & "ì"
Case "Ì"
NewString$ = NewString$ & "Ì"
Case "ô"
NewString$ = NewString$ & "ô"
Case "Ô"
NewString$ = NewString$ & "Ô"
Case "ó"
NewString$ = NewString$ & "ó"
Case "Ó"
NewString$ = NewString$ & "Ó"
Case "ò"
NewString$ = NewString$ & "ò"
Case "Ò"
NewString$ = NewString$ & "Ò"
Case "ú"
NewString$ = NewString$ & "ú"
Case "Ú"
NewString$ = NewString$ & "Ú"
Case "û"
NewString$ = NewString$ & "û"
Case "Û"
NewString$ = NewString$ & "Û"
Case "ù"
NewString$ = NewString$ & "ù"
Case "Ù"
NewString$ = NewString$ & "Ù"
Case Else '--if no match is specified or found, return with the NextChar item
NewString$ = NewString$ & NextChar$
End Select
End If

Next

ConvertFrench = NewString$

End Function
________________
I used this agent to test it ...
Sub Initialize
Dim session As New NotesSession
Dim doc As NotesDocument
Set doc = session.DocumentContext

Print {Content-Type:text/plain} ' suppresses "Notes" generated <BODY> tag
Print {Content-Type:text/html}
Print "<HTML>"
Print "<BODY>"
Print "<H2>TEST</H2>"

QueryString$ = doc.Query_String(0)
Print QueryString$

Print "</BODY>"
Print "</HTML>"

End Sub

I used this URL to test it ...
http://serverpath/dbpath.nsf/TestFrench ... cute;phone

FYI: You could actually pass an entire HTML document in the querystring (no spaces though)and use Print
QueryString$ to display it (no conversion needed)...

i.e.
TestFrenchChars?OpenAgent&<H4>This+appears+as+H4</H4>etc.

Pretty Cool huh?
"Plouf..." Anonyme
thierry.ceretto
Posteur expérimenté
Posteur expérimenté
 
Message(s) : 331
Inscrit(e) le : 29 Sep 2005 à 15:55
Localisation : Nancy

Retour vers Chaines de caractères