split string成为crystall报告中的自定义代码

时间:2017-08-15 04:44:33

标签: string vb6

我有这样的字符串

P-123C自动 P-H342非自动系统 P-HH231自动系统 PD 4357JP REF-B130MK3空气系统 BSC-WDB801流程系统

我想要这样的字符串

P-123C P-H342 P-HH231 PD 4357JP REF-B139MK3 BSC-WDB801

请帮助......掌握

1 个答案:

答案 0 :(得分:0)

我试过,不幸的是PD 4357JP因为被空格分开而产生问题。然后因为你的结果似乎仅由上面的字符和数字组成,我试图删除所有较低的字符,结果似乎很好:

Dim sOut As String
Dim sIn As String
Dim sResult As String
Dim i As Long
Dim c As String
sIn = "P-123C automatic P-H342 non automatic system P-HH231 automatic system PD 4357JP REF-B130MK3 air system BSC-WDB801 flow system"
For i = 1 To Len(sIn)
    c = Mid$(sIn, i, 1)
    Select Case Asc(c)
        Case 97 To 122 ' remove lower chars
            ' do nothing
        Case Else
            sOut = sOut & c
            sOut = Replace$(sOut, "  ", " ")
    End Select
Next i
sResult = sOut
Debug.Print sResult
'Is: P-123C P-H342 P-HH231 PD 4357JP REF-B130MK3 BSC-WDB801