替换字符 倒数指定一个字符 Topic is solved

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

hhh246801

替换字符 倒数指定一个字符  Topic is solved

Post by hhh246801 » 22 Nov 2022, 08:25

abcd:abcd@[email protected]
1234:1234@[email protected]
sdfsdf:sdfsdsf@dfdf@dfdfcom

请问如何替换每段倒数第一个@

下面命令只能替换全部@
test := RegExReplace(test,"@","" )

fwejifjjwk2
Posts: 89
Joined: 10 Aug 2019, 01:49

Re: 替换字符 倒数指定一个字符

Post by fwejifjjwk2 » 01 Dec 2022, 05:50

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")

yesorno
Posts: 2
Joined: 28 Jul 2019, 03:43

Re: 替换字符 倒数指定一个字符

Post by yesorno » 07 Dec 2022, 10:01

RegExReplace(str, "(.*)@(.*)", "$1$2")

Post Reply

Return to “请求帮助”