返回列表 发帖
vbs:
Randomize()
For i=1 To 2
r = Rnd*a.count\1
        msgbox ((a.Items())(r))
a.Remove(r)
NextCOPY
话说 js 操作数组元素或者对象属性比起 vbs 方便得多...

我更喜欢用 gnu,不过 sort 的 -R 选项得看版本:
gnu_sort -R "D:\OperaZ_Y\英语谚语.txt" | sed "1,2!d"COPY
powershell 也是很好的选择,尽管它的设计用途并不是处理文本:
get-content "D:\OperaZ_Y\英语谚语.txt" | get-random -count 2COPY

TOP

噢,发现理解错了....................

TOP

本帖最后由 CrLf 于 2014-4-15 17:49 编辑

那更简单了:
randomize
set fso = CreateObject("Scripting.Filesystemobject")
set file = fso.OpenTextFile("英语谚语.txt")
text = file.ReadAll
a = Split(text,vbCrLf)
file.Close
h = (rnd*UBound(a)\2)*2
str = a(h) & vbCrLf & a(h+1)
'msgbox str
setClip str
Set WshShell= WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "^v"
WshShell.SendKeys "^{ENTER}"
Sub setClip(str)
Dim Form, TextBox
Set Form = CreateObject("Forms.Form.1")
Set TextBox = Form.Controls.Add("Forms.TextBox.1").Object
TextBox.MultiLine = True
TextBox.Text = str
TextBox.SelStart = 0
TextBox.SelLength = TextBox.TextLength
TextBox.Copy
End SubCOPY
setClip 修改自 demon 的博客里的内容,这样就不需要第三方支持了(如果 com 可以不算的话)

TOP

话说 opera 不能用 userscript 操作 dom 吗?还要这么复制粘贴

TOP

回复 8# 我来了


    多写了个 r,已修改。
    setClip 是 vbs 脚本里写的过程,不是外部命令

TOP

回复 10# 我来了


    原来以为是随机提取两行,你的意思不是随机提取相邻的中英文各一行吗?

TOP

回复 11# 我来了


    WIN X64 企业版没有 Forms.Form.1 ?那你还是用 nircmd 吧,或者学一下 au3/autohotkey,实现这个既精确又简单

TOP

返回列表