找回密码
 加入
搜索
查看: 3815|回复: 9

[AU3基础] (已解决)关于正则双引号问题?

  [复制链接]
发表于 2010-9-17 17:44:30 | 显示全部楼层 |阅读模式
本帖最后由 minghui 于 2010-9-20 21:39 编辑

#include <GUIConstants.au3>

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 354, 292, 192, 124)
$Input1 = GUICtrlCreateInput('', 32, 16, 281, 21)
GUICtrlSetData(-1, 'CNTV-CBox 网络电视客户端  安装')
$Input2 = GUICtrlCreateInput('', 32, 48, 281, 21)
GUICtrlSetData(-1, '欢迎使用"CNTV-CBox 网络电视客户端"安装向导')
$Edit1 = GUICtrlCreateEdit("", 32, 80, 281, 145)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Button1", 32, 240, 281, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

                Case $Button1
                    ;GUICtrlSetData($Edit1, "WinActivate("&'"'&GUICtrlRead($Input1)&'"'&", "&'"'&GUICtrlRead($Input2)&'"'&")"&@CRLF)
        EndSwitch
WEnd
主要想实现如下功能
1, 当$Input2文本内容包含有双引号时就在文本框内写入带有单双引号的文本
2, 当$Input2文本内容为"空"或没有包含双引号时就只在文本框内写入双引号(注;不包含单引号)

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-9-17 17:56:06 | 显示全部楼层
就是将双引号替换成单引号是吧?借你的按钮用下。

#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 350, 290)
$Input1 = GUICtrlCreateInput('', 32, 16, 281, 21)
GUICtrlSetData(-1, 'CNTV-CBox 网络电视客户端  安装')
$Input2 = GUICtrlCreateInput('', 32, 48, 281, 21)
GUICtrlSetData(-1, '欢迎使用"CNTV-CBox 网络电视客户端"安装向导')
$Edit1 = GUICtrlCreateEdit("", 32, 80, 281, 145)
$Button1 = GUICtrlCreateButton("Button1", 32, 240, 281, 25)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case - 3
                        Exit

                Case $Button1
                        $sText = GUICtrlRead($Input2)
                        If StringRegExp($sText, '"|“|”') Then
                                MsgBox(0, '', StringRegExpReplace($sText, '"|“|”', "'"))
                        Else
                                MsgBox(0, '', '控件文本不含双引号')
                        EndIf
        EndSwitch
WEnd
发表于 2010-9-17 17:57:07 | 显示全部楼层
本帖最后由 afan 于 2010-9-17 18:07 编辑

木子恢复得挺快呀~
$Form1 = GUICreate("Form1", 354, 292, 192, 124)
$Input1 = GUICtrlCreateInput('', 32, 16, 281, 21)
GUICtrlSetData(-1, 'CNTV-CBox 网络电视客户端  安装')
$Input2 = GUICtrlCreateInput('', 32, 48, 281, 21)
GUICtrlSetData(-1, '欢迎使用"CNTV-CBox 网络电视客户端"安装向导')
$Edit1 = GUICtrlCreateEdit("", 32, 80, 281, 145)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Button1", 32, 240, 281, 25)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit

                Case $Button1
                        $sI1 = GUICtrlRead($Input1)
                        If StringRegExp($sI1, '"') Then
                                $sI1 = "'" & $sI1 & "'"
                        Else
                                $sI1 = '"' & $sI1 & '"'
                        Endif
                        $sI2 = GUICtrlRead($Input2)
                        If StringRegExp($sI2, '"') Then
                                $sI2 = "'" & $sI2 & "'"
                        Else
                                $sI2 = '"' & $sI2 & '"'
                        Endif
                        GUICtrlSetData($Edit1, "WinActivate(" & $sI1 & ", " & $sI2 & ")" & @CRLF)
        EndSwitch
WEnd


另注:如果没有单引号的介入其实就都用单引号就OK了
$sI1 = "'" & GUICtrlRead($Input1) & "'"
$sI2 = "'" & GUICtrlRead($Input2) & "'"
GUICtrlSetData($Edit1, "WinActivate(" & $sI1 & ", " & $sI2 & ")" & @CRLF)
如果有单双引号混搭的情况可参考一下此贴 http://www.autoitx.com/thread-10929-1-1.html
 楼主| 发表于 2010-9-17 18:01:53 | 显示全部楼层
本帖最后由 minghui 于 2010-9-17 18:03 编辑

不好意思啊!  可能我表达的不清楚
我的意思是当文本内包含有双引号时就写成下面这样的样式
包含双引号时
WinActivate("CNTV-CBox 网络电视客户端  安装", '"欢迎使用"CNTV-CBox 网络电视客户端"安装向导"')
没包含双引号时
WinActivate("CNTV-CBox 网络电视客户端  安装", "欢迎使用CNTV-CBox 网络电视客户端安装向导")
 楼主| 发表于 2010-9-17 18:09:20 | 显示全部楼层
谢谢已经解决了,变通一下就可以了
$sI1 = "'" &  $sI1  & "'"
换成
$sI1 = "'" & '"' & $sI1 & '"' & "'"
发表于 2010-9-17 18:10:45 | 显示全部楼层
本帖最后由 afan 于 2010-9-17 18:11 编辑
谢谢已经解决了,变通一下就可以了换成
minghui 发表于 2010-9-17 18:09



    这个是没必要的~
而且,这样的结果就错了…
 楼主| 发表于 2010-9-17 18:14:09 | 显示全部楼层
回复 6# afan
版主的意思是当文本内包含有双引号时,就只要单引号就可以了是吧!
发表于 2010-9-17 18:15:40 | 显示全部楼层
回复 7# minghui


    是的。你测试下就知道了
 楼主| 发表于 2010-9-17 18:16:01 | 显示全部楼层
回复 6# afan
版主的意思是当文本内包含有双引号时,就只要单引号就可以了是吧!
   
谢谢了,试了一下切实是这样的
发表于 2010-9-17 18:17:58 | 显示全部楼层
回复 9# minghui


    所以就如我在3楼所注,如果不考虑单引号则无需判断。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-17 12:12 , Processed in 0.088582 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表