首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

任意给出一个句子一,其中一部分被替换成 VVV+数字的形式 (三个V加数字)形成句子二,如何把句子中的VVVn 在句子一中的子符串原型还原出来

2014-01-26 
任意给出一个句子一,其中一部分被替换成 VVV+数字的形式 (三个V加数字)形成句子二,怎么把句子中的VVVn 在

任意给出一个句子一,其中一部分被替换成 VVV+数字的形式 (三个V加数字)形成句子二,怎么把句子中的VVVn 在句子一中的子符串原型还原出来?
例一:
句一:
Check for continuity between the speaker feed (+) circuit cavities of the radio receiver wire harness connectoror if equipped, the amplifier wire harness connector and the speaker wire harness connector.
句二:
Check for continuity between VVV1  and  VVV2 .

如果句一等于句二,则:
VVV1= the speaker feed (+) circuit cavities of the radio receiver wire harness connectoror if equipped, the amplifier wire harness connector 
VVV2= the speaker wire harness connector


例二:
句一:repair the shorted speaker feed (+) and/or return (-) circuits(s) to the speaker as required.
句二:repair  VVV1  as required.
VVV1=the shorted speaker feed (+) and/or return (-) circuits(s) to the speaker

问题,任意给出一个句子一,其中一部分被替换成 VVV+数字的形式 (三个V加数字)形成句子二,怎么把句子中的VVVn 在句子一中的子符串原型还原出来?
或者说,知道“句子一”,“句子二”,求 VVVn在句子一中的字符串值?
[解决办法]


Private Sub Form_Load()
Dim str1, str2, VVVn, buff1, buff2 As String
Dim pos, len1, len2, lenV As Long
str1 = "repair the shorted speaker feed (+) and/or return (-) circuits(s) to the speaker as required."
str2 = "repair VVV1 as required."
len1 = Len(str1)
len2 = Len(str2)
pos = InStr(str2, "VVV") - 1
If pos <> 0 Then
    buff1 = Right(str1, len1 - pos)
End If
buff2 = Right(str2, len2 - pos - 5)
lenV = Len(buff2)
VVVn = Left(buff1, Len(buff1) - 13)
MsgBox " VVVn = " & VVVn
End Sub

[解决办法]
Sub test()
    Dim w1 As String, w2 As String, w3 As String
    Dim i As Integer, j As Integer, wV As String
    w1 = "repair the shorted speaker feed (+) and/or return (-) circuits(s) to the speaker as required."
    w2 = "repair VVV1 as required."
    i = InStr(1, w2, "vvv", vbTextCompare)
    j = InStr(i + 1, w2, " ", vbTextCompare)
    wV = Mid$(w2, i, j - i)
    w3 = Mid$(w1, i, Len(w1) - Len(w2) + j - i)
    Debug.Print wV & "=" & w3
End Sub

[解决办法]
Dim strSource As String, strPattern As String, strSearch As String
Dim p As Long, i As Long

Dim strSItem() As String, strPItem() As String

strSource = "Check for continuity between the speaker feed (+) circuit cavities of the radio receiver wire harness connectoror if equipped, the amplifier wire harness connector and the speaker wire harness connector."
strPattern = "Check for continuity between VVV1  and  VVV2."

i = 1
p = 1
Do
    strSearch = "VVV" & CStr(i)
    p = InStr(p, strPattern, strSearch)
    If p > 0 Then
        strPattern = Replace(strPattern, strSearch, "
[解决办法]
")
        i = i + 1
    Else
        Exit Do
    End If


Loop
    
strPItem = Split(strPattern, "
[解决办法]
")

For i = 0 To UBound(strPItem)
    strSource = Replace(strSource, Trim(strPItem(i)), "
[解决办法]
")
Next i

strSItem = Split(strSource, "
[解决办法]
")

p = 1
For i = 0 To UBound(strSItem)
    If strSItem(i) > "" Then
        Debug.Print "VVV" & CStr(p) & ": " & Trim(strSItem(i))
        p = p + 1
    End If
Next i


结果:
VVV1: the speaker feed (+) circuit cavities of the radio receiver wire harness connectoror if equipped, the amplifier wire harness connector
VVV2: the speaker wire harness connector

热点排行