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

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: 替换字符 倒数指定一个字符

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

Post by yesorno » 07 Dec 2022, 10:01

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

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

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

Post by hhh246801 » 22 Nov 2022, 08:25

abcd:abcd@asdfsdf@adfsdf.com
1234:1234@1231231212@sdfsdf.com
sdfsdf:sdfsdsf@dfdf@dfdfcom

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

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

Top