Hi all,

I have string like this: JK-501-3556-25-A-03#C
I would to extract the middle part without dash which suppose to look like this:355625

I wrote the code this way, but the string extracted looks like this: 3556-25355625

For i = 1 To Len(cbPN.Text)
 If Mid(cbPN.Text, i, 1) = "-" Then
 Else
 strExtract = strExtract & Mid(cbPN.Text, i, 1)
 End If
 Next

Please anyone outhere help me to solve this problem. Thank you.

I don't know if this will help. This is based on the fact that you know where to get the middle part. Let me know if this helped.

Dim i As Integer, strExtract As String

For i = 1 To Len(cbPN.Text)
 If Mid(cbPN.Text, i, 1) = "-" Or Not IsNumeric(Mid(cbPN.Text, i, 1)) Then
 'Clear all dashes AND letters
        Else
    strExtract = strExtract & Mid(cbPN.Text, i, 1)
 End If
 Next

Text2.Text = strExtract
'Now we know that the returned value is only numbers
'We can now remove the first 3 numbers (assuming that
'we know it is 3!!!), and return the first 6 after that
'to give us the value of 355625
Text2.Text = Mid(Text2.Text, 4, 6)
Dim MyArray() As String, MyString As String
MyArray = Split("JK-501-3556-25-A-03#C", "-")
MyString = MyArray(0) & "-" & MyArray(1) & "-" & MyArray(2) & MyArray(3) & "-" & MyArray(4) & "-" & MyArray(5)
MsgBox MyString

Good Luck

Hi guys, thanks a lot, those examples really helped a lot in other programs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.