如何计算在VBA中的string前的空格的数量?
我有一个YAML文件,我正在阅读使用VBA Excel插件。 我得到每行的string。 我需要计算第一行前面的空白空间的数量,以便它成为find下一个键的标记。 让我知道如何做到这一点。
Option Explicit Function empty_spaces(str_input) empty_spaces = Len(str_input) - Len(LTrim(str_input)) End Function
harun24hr,你的答案不适用于“我的string”和类似的。
使用以下代码:
Sub SpaceInFront() Dim testString Dim SpaceCount As Integer testString = " My String" SpaceCount = Len(testString) - Len(Trim(testString)) Debug.Print SpaceCount End Sub