使用Autohotkey删除点后的字符串的最后n个字符 [英] Remove last n characters of string after the dot with Autohotkey
本文介绍了使用Autohotkey删除点后的字符串的最后n个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用自动快捷键.
I am using Autohotkey.
我有一个看起来像这个S523.WW.E.SIMA
的字符串.我想删除点后字符串的最后几个字符(包括点本身).因此,删除后,字符串将类似于S523.WW.E
.
I have a string that looks like this S523.WW.E.SIMA
. I want to remove the last few characters of the string after the dot (including the dot itself). So, after the removal, the string will look like S523.WW.E
.
这可能看起来像是一个简单的问题,但是我只是无法弄清楚在Autohotkey中使用可用的字符串函数.如何使用Autohotkey完成此操作?非常感谢.
This may look like a simple question but I just cannot figure out using the available string functions in Autohotkey. How can this be done using Autohotkey? Thank you very much.
推荐答案
示例1(的最后一个索引)
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
See InStr
See SubStr
; 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]
}
示例3(RegExMatch)
; Extract everything up until the last dot
RegExMatch(string, "(.*)\.", result)
msgbox % result1
示例4(RegExReplace)
; RegExReplace to remove everything, starting with the last dot
result := RegExReplace(string, "\.[^\.]+$", "")
这篇关于使用Autohotkey删除点后的字符串的最后n个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文