本文介绍了将字符串拆分为字符数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 VBA 字符串拆分为字符数组?

How is it possible to split a VBA string into an array of characters?

我试过 Split(my_string, "") 但这没有用.

I tried Split(my_string, "") but this didn't work.

推荐答案

最安全 &最简单的就是循环;

Safest & simplest is to just loop;

Dim buff() As String
ReDim buff(Len(my_string) - 1)
For i = 1 To Len(my_string)
    buff(i - 1) = Mid$(my_string, i, 1)
Next

如果你保证只使用ansi字符,你可以;

If your guaranteed to use ansi characters only you can;

Dim buff() As String
buff = Split(StrConv(my_string, vbUnicode), Chr$(0))
ReDim Preserve buff(UBound(buff) - 1)

这篇关于将字符串拆分为字符数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:25