excel - VBA 函数来测试字符串的缩写
问题描述
我有以下函数(UDF),它完全符合我的要求,但是我想知道是否可以没有字典(带有预定义缩写的数组)?该函数将字符串转换为正确的大小写,忽略缩写(总是大写)。我希望函数是动态的,这样每次数据更改时我都不必更改数组中的缩写(缩写的数量可能会大大增加)。这可能吗?
Public Function PROPERCASE(s As String)
'Variables
Dim bResult As Boolean
Dim i As Integer, j As Integer
Dim c As Variant, v As Variant
c = Array("ENIS", "ENIR", "PCS", "WFC", "MBS", "SIE", "SCI", "TCS", "I/O", "SNMP", _
"RX", "TX", "PSU", "UPS", "UHF", "FXO", "FXS", "VOIP", "TIN", "NMS", _
"AC", "DC", "VRS", "TETRA", "NTP", "PoE", "TEMPEST") 'Abbreviations to ignore
v = Split(Replace(s, "/", " / "), " ") 'Separates the words
For j = LBound(v) To UBound(v)
For i = LBound(c) To UBound(c)
If StrComp(Replace(Replace(v(j), "(", ""), ")", ""), c(i), vbBinaryCompare) = 0 Or (v(j) Like "*#*") Then bResult = True: Exit For Else bResult = False
Next i
If bResult = False Then v(j) = StrConv(v(j), vbProperCase): bResult = False
Next j
PROPERCASE = Replace(Join(v, " "), " / ", "/") 'Joins the words
End Function
任何帮助将不胜感激。
解决方案
推荐阅读
- sql - 外联当量 - GBQ
- c++ - 这个帕斯卡三角形中的阶乘函数代码有什么问题?
- mysql - 使用 WHERE 和索引的超慢 MySQL 查询
- spring - 将 vaadin 流启动器应用程序部署到 WebSphere Liberty 时出错
- javascript - 为什么我无法使用以下代码将文件上传到 AWS S3?
- elixir - 不同元素更改时调用 LiveView update() 挂钩
- python - 当提到(未调用)内置退出函数时,为什么 PyInstaller 可执行文件会终止?
- android - 在android中显示自定义图像:XML config
- angular - “AngularFireAuth”类型上不存在属性“数据库”
- deep-learning - 使用预训练的 VGG-16 验证损失和准确性都在增加