- 大学三年级
- 325019
- 734
- 13
- 1738 朵
- 2853 个
- 844 个
- 20600
- 2009-10-23
|
1#
t
T
发表于 2024-07-20 11:54
|
|只看楼主
大家好,我是郭立员~ 前言写一些我常用的功能性的代码段: (1) 不重复的写入文本 - Dim path = "/sdcard/pictures/账号.txt"
- Function FileWrite(path,str)
- Dim arr = file.readlines(path)
- If Len(arr) = 0 Then
- File.Write(path, str&"\r\n")
- Else
- For i = 1 To Len(arr)
- If arr[i] = str Then
- Exit For
- End If
- If i = Len(arr) Then
- File.Append(path, str&"\r\n")
- End If
- Next
- End If
- End Function
复制代码(2)文本读一行删一行 - Dim path = "/sdcard/pictures/账号.txt"
- TracePrint fileReadLine(path)
- Function fileReadLine(path)
- Dim str = file.readline(path,1)
- If Len(str) > 0 Then
- file.DeleteLine path, 1
- fileReadLine = str
- Else
- TracePrint "文本内容已空"
- End If
- End Function
复制代码(3)获取小精灵包名 - TracePrint getPackage()
- Function getPackage()
- Dim path = GetTempDir()
- Dim arr = split(path, "/")
- getPackage = arr[ubound(arr)]
- End Function
复制代码(4)对数组进行排序 - Dim arr = {13,7,4,18,17,26,7,19,10}
- Dim ret = sorted(arr)
- TracePrint encode.TableToJson(ret)
- Function sorted(arr)
- Dim num
- For UBOUND(arr)
- For i = 1 To UBOUND(arr)
- If arr[i] > arr[i + 1] Then
- num = arr[i]
- arr[i] = arr[i + 1]
- arr[i+1] = num
- End If
- Next
- Next
- sorted = arr
- End Function
复制代码(5)查找数组最大值和最小值 - Dim Matharr = {13,7,4,18,17,26,7,19,10}
- Traceprint "数组中最大值:",MathMax (arr)
- TracePrint Encode.TableToJson(arr) //修改了数组内容
- Traceprint "数组中最小值:",MathMin (arr)
- Function MathMax(arr)
- For i = 1 To UBOUND(arr)
- If arr[i] > arr[i + 1] Then
- arr[i+1] = arr[i]
- End If
- Next
- MathMax = arr[len(arr)]
- End Function
- Function MathMin(arr)
- For i = 1 To UBOUND(arr)
- If arr[i] < arr[i + 1] Then
- arr[i+1] = arr[i]
- End If
- Next
- MathMin = arr[len(arr)]
- End Function
复制代码(6)拆分打码平台的坐标返回值 - Import "shanhai.lua"
- Dim ret = "435,147|684,352|224,66|451,116"
- splitCoordinate(ret)
- Function splitCoordinate(ret)
- Dim arr = shanhai.RegexFindEx(ret,"(%d+),(%d+)")
- For i = 1 To Len(arr)
- TracePrint arr[i][1],arr[i][2]
- Next
- End Function
复制代码(7)字符串拆分成数组 - Dim str = "12345456"
- Dim arr = strAsArr(str)
- TracePrint encode.TableToJson(arr)
- Function strAsArr(str)
- Dim arr = {null}
- For i = 1 To Len(str)
- arr[i] = mid(str,i,1)
- Next
- strAsArr = arr
- End Function
复制代码(8)定时脚本 - import "shanhai.lua"
- Dim 小时 = 19
- Dim 分钟 = 44
- If fixedTime(小时, 分钟) Then
- TracePrint "到时间了"
- Else
- TracePrint "没有到时间"
- End If
- Function fixedTime(h, m)
- Dim t = Now()
- Dim arr_time = shanhai.RegexFind(t,"(%d+):")
- TracePrint arr_time[1],arr_time[2]
- If cint(arr_time[1]) = cint(h) and cint(arr_time[2]) = cint(m) Then
- fixedTime = true
- End If
- End Function
复制代码先写这么多,以后想到其他的再补充。
|