我有字符串,我只想从字符串中导出文本(字符串中的分隔符是“_”)。 例如:仅从字符串中导出文本,VBA
字符串:Prijem_LPLC_MO-234_333333
提取物:Prijem_LPLC
我的代码:
Public Function komentar(text_string As String) As String
Dim text() As String
Dim pom As String
text() = Split(text_string, "_")
komentar = ""
For i = LBound(text) To UBound(text) - 1
If Application.IsText(text(i)) Then
komentar = komentar & "_" & text(i)
End If
Next i
End Function
但它拷贝满弦与 “_” 在开头。
是的,我现在明白了。然后,实际上,我需要检查该子字符串中是否有数字字符,然后不要在提取中包含该子字符串。或者如果在一个子字符串中都是字母,那么将其包含在提取中。 – user155754
对于字母条件,您可以检查字符串中每个字符的ASCII或使用类似[正则表达式](https://www.experts-exchange.com/articles/1336/Using-Regular-Expressions-in-Visual - 基本换应用程序和视听-Basic的6.html)。经过小小的谷歌搜索,我发现[这](https://techniclee.wordpress.com/2010/07/21/isletter-function-for-vba/)和[this](https://stackoverflow.com/questions/29633517 /如何-可以-I-检查-IF-A-字符串只,包含-字母)。 – Loowood
谢谢,这可能会诀窍。 – user155754