用vbs编写的将vbs代码中的Replace转换成Java的replace(第一版)

13 篇文章 0 订阅


之前用vbs写过的一大段代码,现要用Java重写,工作量非常大,原想用正则表达式的方式去实现,但当代码中过于复杂时,正则表达式还是达不到效果,于是用vbs的土办法编写一个先将其中Replace转换成Java的replace,代码如下:

Function vbsToJava_Replace(content)
content = Replace(content, "replace", "Replace")

'替换Replace
startA = instr(content,"Replace(")
do while startA>0
	findCount = 1
	startA1 = startA + len("Replace(")
	endA1 = startA
	endA2 = startA
	do while findCount>0 and (endA1 >0 or endA2>0)
		endA1 = instr(startA1, content, "(")
		do while mid(content, endA1 + 1, 1)="""" and mid(content, endA1 - 1, 1)=""""
			endA1 = endA1 + 1
			endA1 = instr(endA1, content, "(")
		loop 
		endA2 = instr(startA1, content, ")")
		do while mid(content, endA2 + 1, 1)="""" and  mid(content, endA2 - 1, 1)=""""
			endA2 = endA2 + 1
			endA2 = instr(endA2, content, ")")
		loop
		If (endA1>0 and endA2>0) Then
			If (endA1<endA2) Then
				findCount = findCount + 1
				startA1 = endA1 + 1
			Else
				findCount = findCount - 1
				startA1 = endA2 + 1
			End If
		ElseIf (endA1>0) Then
			findCount = findCount + 1
			startA1 = endA1 + 1
		ElseIf (endA2>0) Then
			findCount = findCount - 1
			startA1 = endA2 + 1
		End If
	loop
	endA = startA1
	tmpStr1 = mid(content, startA, endA-startA)
	Wscript.echo tmpStr1
	
	tmpStr2 = tmpStr1
	tmpStr3 = ""
	startA2 = instr(tmpStr2, "Replace(")
	do while startA2>0
		preStr = ""
		nextStr = ""
		If startA2<>1 Then
			preStr = Trim(mid(tmpStr2, 1, startA2 -1))
		End If
		startA2 = startA2 + len("Replace(")		
		endA2tmp = len(tmpStr2)
		do 
			endA2 = instrRev(tmpStr2, ",", endA2tmp)
			tmpStr2tmp = mid(tmpStr2, endA2, len(tmpStr2) - endA2)
			yhCount = 0
			yhHas = instr(tmpStr2tmp, """")
			do while yhHas>0				
				yhCount = yhCount + 1
				yhHas = instr(yhHas + 1, tmpStr2tmp, """")
			loop
			endA2tmp = endA2 - 1
		loop while (yhCount mod 2 =1)

		If (endA2>0) Then			
			do
				endA2 = endA2 - 1
				endA2 = instrRev(tmpStr2, ",", endA2)
				tmpStr2tmp = mid(tmpStr2, endA2, len(tmpStr2) - endA2)
				yhCount = 0
				yhHas = instr(tmpStr2tmp, """")
				do while yhHas>0				
					yhCount = yhCount + 1
					yhHas = instr(yhHas + 1, tmpStr2tmp, """")
				loop
			loop while (yhCount mod 2 =1)			
		End If

		If (len(preStr)>0) Then
			If (endA2>0) Then			
				do
					endA2 = endA2 - 1
					endA2 = instrRev(tmpStr2, ",", endA2)
					tmpStr2tmp = mid(tmpStr2, endA2, len(tmpStr2) - endA2)
					yhCount = 0
					yhHas = instr(tmpStr2tmp, """")
					do while yhHas>0				
						yhCount = yhCount + 1
						yhHas = instr(yhHas + 1, tmpStr2tmp, """")
					loop
				loop while (yhCount mod 2 =1)			
			End If
		End If

		If (endA2>0) Then
			tmpStr21 = mid(tmpStr2, startA2, endA2 - startA2)
			tmpStr3 = ".replace(" & mid(tmpStr2, endA2+1, len(tmpStr2)-endA2) & tmpStr3
			tmpStr2 = preStr & tmpStr21
			'Wscript.echo tmpStr3
		End If
		startA2 = instr(tmpStr2, "Replace(")
	loop
	tmpStr3 = tmpStr2 & tmpStr3
	Wscript.echo tmpStr1 & vbcrlf & tmpStr3
	content = Replace(content, tmpStr1, tmpStr3)
	startA = instr(content,"Replace(")
loop
vbsToJava_Replace = content
End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值