计算机字符连接函数,用函数简化你的字符串连接语句

'你是否非常讨厌 用 & 一大串的连接变量?

'你是否不得不经常使用""与"""" ?

'就好像这样:

'strFilter = strFilter & " and [" & strFldname & "] like """ & strValue & """"

'

'strSql ="insert into tblpubStyle (Class,Prop,Value,Type,[Set],memo,flag) values ('" & _

' ctl.ControlType & "','" & _

' prp.Name & "','" & _

' prp.Value & "','" & _

' prp.Type & "', " & _

' 2 & "," & _

' "' ', " & _

' false ")"

'

'strCnn = "Provider=sqloledb;" & _

' "Data Source=" & strServerName & ";" & _

' "Initial Catalog=" & strDbname & ";" & _

' "User Id=" & strUid & ";" & _

' "Password=" & strPwd & ";"

'

'用它,gCombinationString,这个十分简单的函数,让冗长的代码更简洁,增强语句可读性

'以下是它的使用典型形式:

'strFilter = gCombinationString( "$1 and [$2] like ""$3""",strFilter,strFldname,strValue)

'strCnn= gCombinationString("Provider=sqloledb;Data Source=$1;Initial Catalog=$2;User Id=$3;Password=$4;",_

' strServerName ,strDbname ,strUid, strPwd)

'参数个数不限,参数类型不限

' strSql = gCombinationString("insert into tblpubStyle (Class,Prop,Value,Type,[Set],memo,flag) " & _

' " values ('$1','$2','$3','$4',$5,$6)", _

' ctl.ControlType, prp.Name, prp.Value, prp.Type, 2, False)

'

Const strCharPre = "$"

Dim varItem As Variant

Dim i As Integer

i = 0

For Each varItem In Para

i = i + 1

strText = VBA.Replace(strText, strCharPre & i, varItem)

strText = VBA.Replace(strText, strCharPre & "\", strCharPre)

Next

gCombinationString = strText

End Function来源:-计算机二级考试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值