让SQL标签支持REPLACE!
声名:如果你不会,请不要随便改动,如果出现一些问题,请自已负责,谢谢!
使用REPLACE标签的方法
{$REPLACE(aa||bb,,bbb|cc,,ccc)} 查找bb替换bbb,和查找cc替换ccc 支持多替换,中间用|分开,aa是字符串,注意,这些字符串都不需要添加双引号
例:{$REPLACE(我们去上街||我们,,我|上街,,逛街)}
输出结果是:我去逛街
打开KS_Cls\Kesion.Label.SQLCls.asp
查找
ReplaceCondition=TempStr
End Function
在下面添加
'字符替换 {$REPLACE(aa||bb,,bbb|cc,,ccc)}查找bb替换bbb,和查找cc替换ccc 支持多替换,中间用|分开
Function ReplaceCondition1(byval str)
Dim regEx, Matches, Match, TempStr
Dim FieldParam,FieldParamArr,ReturnFieldValue,FieldParamArr1,FieldParamArr2,k,re1,re2,re3
re1="||"
re2="|"
re3=",,"
're1,re2,re3可以换自己喜欢的符号,不容易出冲突的符号
on error resume next
Set regEx = New RegExp
regEx.Pattern = "\{\$REPLACE\([^{\$}]*\)\}"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(str)
TempStr=str
For Each Match In Matches
FieldParam = Replace(Replace(Match.Value,"{$REPLACE(",""),")}","")
FieldParamArr = Split(FieldParam,re1)
if instr(FieldParamArr(1),re2)=0 and instr(FieldParamArr(1),re3)>0 then
FieldParamArr2=Split(FieldParamArr(1),re3)
ReturnFieldValue=Replace(FieldParamArr(0),FieldParamArr2(0),FieldParamArr2(1))
elseif instr(FieldParamArr(1),re2)>0 then
ReturnFieldValue=Replace(Replace(Match.Value,"{$REPLACE(",""),")}","")
FieldParamArr1 =Split(FieldParamArr(1),re2)
for k=0 to Ubound(FieldParamArr1)
if k=0 then ReturnFieldValue=FieldParamArr(0)
FieldParamArr2=Split(FieldParamArr1(k),re3)
ReturnFieldValue=Replace(ReturnFieldValue,FieldParamArr2(0),FieldParamArr2(1))
next
end if
if err then
err.clear
else
TempStr=Replace(TempStr,"{$REPLACE(" &FieldParam &")}",ReturnFieldValue)
end if
Next
ReplaceCondition1=TempStr
End Function
‘=============分界线================
查找 CleanLabel=ReplaceCondition(Replace(Content,"$KS:Page$",vbcrlf))
替换
CleanLabel=ReplaceCondition1(Replace(Content,"$KS:Page$",vbcrlf))
CleanLabel=ReplaceCondition(CleanLabel)
查找 For i=0 to objNode.ChildNodes.length-1
set objAtr=objNode.ChildNodes.item(i)
根据下面的红字体进行添加
Str=Replace(Replace(Replace(Replace(Replace(Replace(objAtr.Attributes.item(2).Text,"{$Field","{#Field"),"{$AutoID}","{#AutoID}"),"{$IF","{#IF"),"{$Param","{#Param"),"{$GetItemUrl}","{#GetItemUrl}"),"{$REPLACE","{#REPLACE")
'避免Field字段被替换掉,先转为#
Str=Rcls.ReplaceGeneralLabelContent(Str)
Str=Replace(Replace(Replace(Replace(Replace(Str,"{#Field","{$Field"),"{#AutoID}","{$AutoID}"),"{#IF","{$IF"),"{#Param","{$Param"),"{#REPLACE","{$REPLACE")
红色为添加部分
====================================================
8.5发现个问题,如下
{$REPLACE(我们有$10块||10,,20)}
如果内部有$就无法运行了。所以我们要调整一下,
查找
regEx.Pattern = "\{\$REPLACE\([^{\$}]*\)\}"
替换
regEx.Pattern = "\{\$REPLACE\([^{}]*\)\}"
我想IF里面如果也有这个符号,应该也会 出问题,修改方法和这个一样~!
"\{\$REPLACE\([^{}]*\)\}"这段可能不是最正确的,但能力有限,先用着。官方能提点一下那就最好不过了。