VB / VBA快速字符串连接类

介绍 (Introduction)

在最近针对Excel社区的 article for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no one had written an EE article on a general purpose fast concatenation function for VB and VBA developers.  The VB.Net community enjoys the StringBuilder class and that (fast concatenation) is a missing functionality for the VB/VBA developer. 文章中,我展示了Excel Concatenate()函数的改进版本。 在撰写该文章时,我意识到没有人针对VB和VBA开发人员撰写过有关通用快速连接功能的EE文章。 VB.Net社区喜欢StringBuilder类,而VB / VBA开发人员则缺少(快速串联)功能。

If you are interested in the different performance characteristics of the intrinsic VB concatenation operators (& and +) and alternatives, please look at the prior article's attached VB project files and performance summaries.

如果您对固有VB串联运算符(&和+)和替代项的不同性能特征感兴趣,请查看上一篇文章随附的VB项目文件和性能摘要。

There are several different development environments in which to create and consume this functionality.  I will use an Office 2003 environment for these examples.

有几种不同的开发环境可在其中创建和使用此功能。 这些示例将使用Office 2003环境。

设计课程 (Designing Our Class)

让我们穿上OOP护目镜片刻,讨论一下我们的设计。 我们需要将字符串追加到对象中并检索串联的字符串。 作为一个不错的功能,让我们提供在连接的字符串之间插入一些定界符文本的功能。

We will need an ADD method that is passed a string.

我们将需要一个传递字符串的ADD方法。

We will need a TEXT property (read/write = set/get).

我们将需要一个TEXT属性(读/写=设置/获取)。

We will need a DELIMITER property (read/write = set/get).

我们将需要一个DELIMITER属性(读/写=设置/获取)。

We want our class to perform well, so we will add fast performance as decision criteria.

我们希望我们的班级表现良好,因此我们将快速表现作为决策标准。

创建课程模块 (Creating Your Class Module)

1.添加模块 (1. Add the module)

Open your code window (Alt+F11)

打开您的代码窗口(Alt + F11)

Insert | Class Module

插入| 类模块

This will add a Class Modules node to your current project and add a Class# module, where # is a sequential number, starting with 1.

这将在当前项目中添加一个Class Modules节点,并添加一个Class 模块&#

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VBA中,判断一个字符串不为空可以使用以下方法: 1. 使用Len函数判断字符串的长度是否大于0。如果字符串的长度大于0,则表示字符串不为空。例如: ``` If Len(str) > 0 Then ' 字符串不为空的处理 End If ``` 2. 使用IsEmpty函数判断字符串是否为空。需要注意的是,IsEmpty函数对于vbNullString会返回True,但对于空白字符串不会返回True。例如: ``` If Not IsEmpty(str) Then ' 字符串不为空的处理 End If ``` 3. 使用vbNullString常量判断字符串是否为null。vbNullString表示一个empty字符串,与空白字符串不同。可以使用vbNullString和字符串进行比较来判断字符串是否为空。例如: ``` If str <> vbNullString Then ' 字符串不为空的处理 End If ``` 4. 使用Trim函数去除字符串两端的空格后,再判断字符串的长度是否大于0。例如: ``` If Len(Trim(str)) > 0 Then ' 字符串不为空的处理 End If ``` 以上是在VBA中判断字符串不为空的几种常见方法。根据具体的需求和场景,选择适合的方法来判断字符串是否为空。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [vba 判断文本框内容是否为空_Excel/VBA编程用户交互函数(二)——InputBox()函数和inputbox方法...](https://blog.csdn.net/weixin_39754831/article/details/110308628)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [VB中判断空的几种方法,Null, Missing, Empty, Nothing, vbNullString区别](https://blog.csdn.net/CharmaineXia/article/details/105351676)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值