abcd:abcd@asdfsdf@adfsdf.com
1234:1234@1231231212@sdfsdf.com
sdfsdf:sdfsdsf@dfdf@dfdfcom
请问如何替换每段倒数第一个@
下面命令只能替换全部@
test := RegExReplace(test,"@","" )
替换字符 倒数指定一个字符 Topic is solved
Moderators: tmplinshi, arcticir
-
- Posts: 89
- Joined: 10 Aug 2019, 01:49
Re: 替换字符 倒数指定一个字符
by v2
測試
Code: Select all
; 移除最後的 @
RemoveLastMouseString(str) {
word_array := StrSplit(str, "@")
EndPos := word_array.Length
NewString := ""
for index, element in word_array
{
if (index = 1) {
NewString := element
} else if (index < EndPos) {
NewString := NewString "@"
NewString := NewString element
} else if (index = EndPos) {
NewString := NewString element
}
}
return NewString
}
Code: Select all
MsgBox( RemoveLastMouseString("") == "")
MsgBox( RemoveLastMouseString("12345") == "12345")
MsgBox( RemoveLastMouseString("1@") == "1")
MsgBox( RemoveLastMouseString("1@2") == "12")
MsgBox( RemoveLastMouseString("1@2@3@4") == "1@2@34")
MsgBox( RemoveLastMouseString("1@@@") == "1@@")
MsgBox( RemoveLastMouseString("1@@@2") == "1@@2")
MsgBox( RemoveLastMouseString("@") == "")
MsgBox( RemoveLastMouseString("@12@@3") == "@12@3")
MsgBox( RemoveLastMouseString("@12@@3") == "@12@3")
MsgBox( RemoveLastMouseString("@1@") == "@1")
MsgBox( RemoveLastMouseString("@1@2@") == "@1@2")
MsgBox( RemoveLastMouseString("@1@2@3") == "@1@23")
MsgBox( RemoveLastMouseString("@1@@") == "@1@")
MsgBox( RemoveLastMouseString("@2") == "2")
MsgBox( RemoveLastMouseString("@@") == "@")
MsgBox( RemoveLastMouseString("@@1@") == "@@1")
MsgBox( RemoveLastMouseString("@@@1") == "@@1")
Re: 替换字符 倒数指定一个字符
RegExReplace(str, "(.*)@(.*)", "$1$2")