Jump to content

GUICtrlRead - Problem with special characters


Recommended Posts

Hi guys :)

 

I have a problem with special characters in this script, or at least with the character "&"

I want to send an email with whatever text is written in the $My_Text variable, and it works fine, but when using "&", it brakes.

The GUI label translates "Batman & Robin" to "Batman _Robin" and the text in the email just ignores everything after the "&" character.

Any ideas on how to fix this? Thx

 

#include <GUIConstantsEx.au3>

GUICreate("GUI", 615, 437, 700, 469)

$Input = GUICtrlCreateInput("Batman & Robin", 16, 110, 194, 21)
$My_Text = GUICtrlRead($Input)

$Label = GUICtrlCreateLabel($My_Text, 104, 196, 100, 100)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

ShellExecute('mailto:' & 'name@email.com' & '?cc=' & 'name2@email.com' & '&subject=Mail subject&body=Text: ' & $My_Text)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Edited by Sky05
Link to comment
Share on other sites

Hi ioa747

Thanks for you answer :)
That doesn't seem to work though, unless I'm doing it wrong?

 

#include <GUIConstantsEx.au3>


GUICreate("GUI", 615, 437, 700, 469)

$Input = GUICtrlCreateInput("Batman & Robin", 16, 110, 194, 21)
$My_Text = GUICtrlRead($Input)
$My_Text = _UnicodeURLEncode($My_Text)


$Label = GUICtrlCreateLabel($My_Text, 104, 196, 100, 100)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

ShellExecute('mailto:' & 'name@email.com' & '?cc=' & 'name2@email.com' & '&subject=Mail subject&body=Text: ' & $My_Text)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd



Func _UnicodeURLEncode($UnicodeURL)
    $UnicodeBinary = StringToBinary ($UnicodeURL, 4)
    $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
    $UnicodeBinaryLength = StringLen($UnicodeBinary2)
    Local $EncodedString
    For $i = 1 To $UnicodeBinaryLength Step 2
        $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
        If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then
            $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar)
        Else
            $EncodedString &= '%' & $UnicodeBinaryChar
        EndIf
    Next
    Return $EncodedString
EndFunc   ;==>_UnicodeURLEncode

 

Link to comment
Share on other sites

Have you try?
this seems to work

; https://www.autoitscript.com/forum/topic/209837-guictrlread-problem-with-special-characters/?do=findComment&comment=1514633

#include <GUIConstantsEx.au3>

GUICreate("GUI", 615, 437, 700, 469)

$Input = GUICtrlCreateInput("Batman & Robin", 16, 110, 194, 21)
$My_Text = GUICtrlRead($Input)

$Label = GUICtrlCreateLabel($My_Text, 104, 196, 100, 100)
GUISetState(@SW_SHOW)

$My_Text = _URIEncode($My_Text)
ShellExecute('mailto:' & 'name@email.com' & '?cc=' & 'name2@email.com' & '&subject=Mail subject&body=Text: ' & $My_Text)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

;----------------------------------------------------------------------------------------
Func _URIEncode($sData)
    ; https://www.autoitscript.com/forum/topic/95850-url-encoding/?tab=comments#comment-689060
    ; Prog@ndy
    Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "")
    Local $nChar
    $sData = ""
    For $i = 1 To $aData[0]
        ; ConsoleWrite($aData[$i] & @CRLF)
        $nChar = Asc($aData[$i])
        Switch $nChar
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $sData &= $aData[$i]
            Case 32
                $sData &= "+"
            Case Else
                $sData &= "%" & Hex($nChar, 2)
        EndSwitch
    Next
    Return $sData
EndFunc   ;==>_URIEncode
;----------------------------------------------------------------------------------------

 

I know that I know nothing

Link to comment
Share on other sites

8 minutes ago, ioa747 said:

Have you try?
this seems to work

; https://www.autoitscript.com/forum/topic/209837-guictrlread-problem-with-special-characters/?do=findComment&comment=1514633

#include <GUIConstantsEx.au3>

GUICreate("GUI", 615, 437, 700, 469)

$Input = GUICtrlCreateInput("Batman & Robin", 16, 110, 194, 21)
$My_Text = GUICtrlRead($Input)

$Label = GUICtrlCreateLabel($My_Text, 104, 196, 100, 100)
GUISetState(@SW_SHOW)

$My_Text = _URIEncode($My_Text)
ShellExecute('mailto:' & 'name@email.com' & '?cc=' & 'name2@email.com' & '&subject=Mail subject&body=Text: ' & $My_Text)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

;----------------------------------------------------------------------------------------
Func _URIEncode($sData)
    ; https://www.autoitscript.com/forum/topic/95850-url-encoding/?tab=comments#comment-689060
    ; Prog@ndy
    Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "")
    Local $nChar
    $sData = ""
    For $i = 1 To $aData[0]
        ; ConsoleWrite($aData[$i] & @CRLF)
        $nChar = Asc($aData[$i])
        Switch $nChar
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $sData &= $aData[$i]
            Case 32
                $sData &= "+"
            Case Else
                $sData &= "%" & Hex($nChar, 2)
        EndSwitch
    Next
    Return $sData
EndFunc   ;==>_URIEncode
;----------------------------------------------------------------------------------------

 

 

Hi again

Thank you, we are getting close. I just tried your code, but this gives me "Batman+&+Robin" with 2 "+" characters.

Edited by Sky05
Link to comment
Share on other sites

hm It works for me, with gmail,

I modified it, try it

;----------------------------------------------------------------------------------------
Func _URIEncode($sData)
    ; https://www.autoitscript.com/forum/topic/95850-url-encoding/?tab=comments#comment-689060
    ; Prog@ndy
    Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "")
    Local $nChar
    $sData = ""
    For $i = 1 To $aData[0]
        ; ConsoleWrite($aData[$i] & @CRLF)
        $nChar = Asc($aData[$i])
        Switch $nChar
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $sData &= $aData[$i]
            Case 32
                $sData &= "%20"
            Case Else
                $sData &= "%" & Hex($nChar, 2)
        EndSwitch
    Next
    Return $sData
EndFunc   ;==>_URIEncode
;----------------------------------------------------------------------------------------

https://www.w3schools.com/tags/ref_urlencode.ASP

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...