用函数简化你地字符串连接语句

2016-02-19 17:31 1 1 收藏

下面是个超简单的用函数简化你地字符串连接语句教程,图老师小编精心挑选推荐,大家行行好,多给几个赞吧,小编吐血跪求~

【 tulaoshi.com - 编程语言 】

'2004/07/27 朱彦志(goodidea) myad@yeah.net

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

'你是否非常讨厌 用 & 一大串的连接变量?
'你是否不得不经常使用""与"""" ?
'就好像这样:
'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)
'

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

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

来源:https://www.tulaoshi.com/n/20160219/1615396.html

延伸阅读
void Split(CString content, CString pattern, CAtlArrayCString& strlist) {     int iPos = content.Find(pattern), iStart = 0;     while (iPos != -1)     {         strlist.Add(content.Mid(iStart, iPos - iStart));     &...
如下表:AggregationTableIdName1赵2钱1孙1李2周 如果想得到下图的聚合结果 IdName1赵孙李2钱周 利用SUM、AVG、COUNT、COUNT(*)、MAX 和 MIN是无法做到的。因为这些都是对数值的聚合。不过我们可以通过自定义函数的方式来解决这个问题。 1.首先建立测试表,并插入测试数据: 代码如下: create table AggregationTable(Id int, [Name] varcha...
之前项目用的数据库是mssql,因此把数据库字符串写在了web.config中,后来客户要求用access,所以直接在web.config中改了连接字符串( 连接用了直接路径) 现在突然想到要把数据库连接字符串改为相对路径,但是如果用server.mappath的话现在麻烦,要在很多文件中改, 有没有办法直接改web.config中的连接字符串,而获得的是相对路径,也就是...
VB官方文档似乎很鼓励使用"无$"类字符串函数,比如:Left、LTrim或者UCase,而不是实现同样功能的Left$、LTrim$和UCase$函数。但是我们必须认识到:前者返回variant类型的数值,当用于字符串表达式中时,最终必须要转换为字符串(string)类型。 因此,在严格要求时间的代码段中,我们应该使用后者,它们将快5-10。 ->
对于针对字符串位置的操作,第一个位置被标记为1。 ASCII(str) 返回字符串 str 的 最左面字符的ASCII代码值。 如果 str 是空字符串, 返回 0 。如果 str 是 NULL ,返回 NULL 。 mysql select ASCII('2'); - 50 mysql select ASCII(2); - 50 mysql select ASCII('dx'); - 100 也可参见ORD()函数。 ORD(str) 如果字符串str最左面字...

经验教程

734

收藏

79
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部