我正在使用自动热键。
我有一个看起来像这样的字符串S523.WW.E.SIMA。我想删除点之后的字符串的最后几个字符(包括点本身)。因此,删除后,字符串将如下所示S523.WW.E。
这可能看起来像一个简单的问题,但我无法弄清楚使用 Autohotkey 中可用的字符串函数。如何使用 Autohotkey 完成此操作?非常感谢。
string := "S523.WW.E.SIMA"
LastDotPos := InStr(string,".",0,0) ; get position of last occurrence of "."
result := SubStr(string,1,LastDotPos-1) ; get substring from start to last dot
MsgBox %result% ; display result
Run Code Online (Sandbox Code Playgroud)
; Split it into the dot-separated parts,
; then join them again excluding the last part
parts := StrSplit(string, ".")
result := ""
Loop % parts.MaxIndex() - 1
{
if(StrLen(result)) {
result .= "."
}
result .= parts[A_Index]
}
Run Code Online (Sandbox Code Playgroud)
; Extract everything up until the last dot
RegExMatch(string, "(.*)\.", result)
msgbox % result1
Run Code Online (Sandbox Code Playgroud)
; RegExReplace to remove everything, starting with the last dot
result := RegExReplace(string, "\.[^\.]+$", "")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2270 次 |
| 最近记录: |