windows-10 - 如何将包含 clipget() 参数的变量加载到单个字符数组中?
问题描述
我在 AutoIt 中编写了一个程序,它会自动http(/s)://(/www.)
从剪贴板中找到的任何内容中删除。
现在我希望它删除 URL 的“页面”规范(结尾),只留下整个站点 URL。
我的第一个猜测是:
############################################################################
(a) put the value of the variable set to clipget() into an array of single characters
### here is my question: #### how do I do that? ###;
############################################################################
(b) point to the third backslash in the string;
(c) set the value to null;
(d) move to the next argument and do the same;
(e) repeat until end of array;
(f) write the values of the array to a variable;
(g) clipput() the string;
(h) exit
我是 AutoIt 的新手。
如何将包含 clipget() 参数的变量加载到数组中?
提前谢谢了
这是我到目前为止所拥有的:
这个应用程序将修剪所有 url 前缀,只留下唯一的 url 字符串
这是我正在努力解决的一个例子。'50' intiger 文字需要用一个函数替换,该函数计算从左边到字符串末尾的第三个反斜杠之间存在的字符数。
#include <MsgBoxConstants.au3>
Local $url = ClipGet()
;#########################################################################
;######################## that '50' needs to be a function ###########
Local $url = StringTrimRight($url, 50)
;#########################################################################
ClipPut($url)
$newurl = ClipGet()
MsgBox($MB_SYSTEMMODAL, "", $newurl)
这是一个我越来越接近我想要的例子的例子。我自己获得了“整个站点”域语法。现在我想 CliptPut() [3] 并删除 MsgBox。我如何捕获 [3] 迭代?
#include <MsgBoxConstants.au3>
Example()
Func Example()
Local $url = CLipGet()
Local $spliturl = StringSplit($url, '/')
For $i = 1 To $spliturl[0]
;#############################################################
;replace 'MsgBox()' with 'ClipPut()' ######################
;i want to CliptPut() '[3]' only
MsgBox($MB_SYSTEMMODAL, "", "$spliturl[" & $i & "] - " &
;somebody help me please ##################################
;#############################################################
$spliturl[$i])
Next
EndFunc
更新
所以现在我有这个:
#include <MsgBoxConstants.au3>
; Press Esc to terminate script, Pause/Break to "pause"
Global $g_bPaused = False
HotKeySet("{PAUSE}", "HotKeyPressed")
HotKeySet("{ESC}", "HotKeyPressed")
HotKeySet("!d", "HotKeyPressed") ; alt-d
HotKeySet("!c", "HotKeyPressed") ; alt-c
While 1
Sleep(100)
WEnd
Func HotKeyPressed()
Switch @HotKeyPressed ; The last hotkey pressed.
Case "{PAUSE}" ; String is the {PAUSE} hotkey.
$g_bPaused = Not $g_bPaused
While $g_bPaused
Sleep(100)
ToolTip('Script is "Paused"', 0, 0)
WEnd
ToolTip("")
Case "{ESC}" ; String is the {ESC} hotkey.
Exit
Case "!d" ; String is the alt + d hotkey.
;####################################################
;#### this is my answer #######################
;set url to the string in clipboard
$url = CLipGet()
;split url into pieces divided by the '/' character
$spliturl = StringSplit($url, '/')
;set $site to third value in '$spliturl'
$site = $spliturl[3]
;export $site to clipboard
ClipPut($site)
;#### looks like it does the trick ##########
;#### does anyone have a better way? ###########
;##################################################
Case "!c" ; String is the alt + c
$sData1 = ClipGet()
;"replace https://" with "" and write the result to clipboard
$sString1 = StringReplace($sData1, "https://www.", Null)
ClipPut($sString1)
$sData1 = ClipGet()
$sData2 = ClipGet()
$sString2 = StringReplace($sData2, "https://", Null)
ClipPut($sString2)
$sData2 = ClipGet()
$sData3 = ClipGet()
;"replace https://" with "" and write the result to clipboard
$sString3 = StringReplace($sData3, "http://www.", Null)
ClipPut($sString3)
$sData3 = ClipGet()
$sData4 = ClipGet()
$sString4 = StringReplace($sData4, "http://", Null)
ClipPut($sString4)
$sData4 = ClipGet()
;##################################################
EndSwitch
EndFunc ;==>HotKeyPressed
解决方案
将变量设置为 ClipGet() 示例:Local $url = ClipGet()
使用 StringSplit() 拆分从 ClipGet() 返回的字符串 使用 '/' 作为 StringSplit() 示例的分隔符:Local $spliturl = StringSplit($url, '/')
将另一个变量设置为由 StringSplit($yourVariable, "/") 创建的数组中的第三个值示例:Local $site = $spliturl[3]
将该值发送回剪贴板示例ClipPut($site)
拍拍自己的肩膀,干得好
解释:在步骤 b)中,您正在制作子字符串数组。在步骤 c) 中,您从数组中选择所需的子字符串并将其放入变量中。剩下的就是蛋糕了。
推荐阅读
- swift - 如何返回一个数组?
- android - Handler 何时与 Looper 关联?
- python - 如何在 python-bash 环境中管理进程?
- sql - 从 SQL 中的列中删除重复值
- javascript - 如何使用 javascript 将 css-grid 元素放入网格容器中
- c# - 如何转换跨度
到 ASCII 字符串? - python - 如何有条件地从数据框中的两列计算的变量中选择行?
- asp.net-core - 在 .Net Core 中自定义 OAuth CallBackPath 控制器
- python-3.x - 有时会抛出错误的文件描述符错误,有时不会
- html - 如何使用 SourceSansPro 匹配设计跨浏览器