This is totally doable. It is unfortunate that you didn't give us a sample of your input and it's corresponding desired result.
Coming late to the game, I'd like to get the rules straight:
1. All of your strings will be 45 real live (not morse) characters. See number 10 below.
2. The only real live characters in any string will be D, I, S, U, 0, 7, 8, and 9.
3. All 45 character strings will begin with the translated letter "D", which is represented in the string by "_.."
4. After the "D", there will always be some multiple of 5 number characters (each represented by 25 morse code elements) that represent the numeric characters 1 through 0 and are translated into a real live number via the table you presented.
5. After at least one of the 5 number characters has come (after the "D"), there will be the string "IS" which is represented by the morse code string ".....".
6. More 5 number strings (25 morse characters each).
7. After at least one of the 5 number characters has come (after the "IS"), there will be the string "IU" which is represented by the morse code string "...._".
8. More 5 number strings (25 morse characters each).
9. The character "I" in morse code which is represented by the mc string "..".
10. If everything I've said above is totally accurate, there's something you haven't told us because there is no way to represent sets of 5 numbers and 6 characters within 45 characters. Proof: 45 - 6 (represented the 6 control characters) = 39; 39 is not evenly divisible by 5. What did we miss?
Does that sum it up accurately (after answering for the anomaly)? If so, this is an incredibly simple task as each of the numeric characters start with at least 3 "_" mc characters and there is absolutely no way possible of misinterpreting the "IS" (".....") or the "IU" ("...._") as part of numbers. Even if the data is error prone, there are some nice features of the coded set that still make it easy to manually interpret the string.
Something like this might work:
Code:
Function TestMorse() As String
Dim l_strOut As String
l_strOut = TranslateDranowebsString("_..______________________........_______________________......_________________________...")
'Debug.Print l_strOut
TestMorse = l_strOut
End Function
Function TranslateDranowebsString(p_strIn As Variant) As String
Dim l_strDElement As String
Dim l_strSElement As String
Dim l_strUElement As String
Dim l_iISLocation As Integer
Dim l_iIULocation As Integer
Dim l_strOut As String
TranslateDranowebsString = "!!Error!!"
If Left(p_strIn, 3) = "_.." And Right(p_strIn, 2) = ".." Then 'it begins with "D" and ends with "I"
On Error GoTo end_function
'29
l_iISLocation = InStr(1, p_strIn, "....._") 'With "IS" somewhere in the middle
If l_iISLocation = 0 Then
TranslateDranowebsString = "!!Error!! - Does not contain 'IS' followed by a number"
GoTo end_function
End If
'59
l_iIULocation = InStr(l_iISLocation + 5 + 5, p_strIn, "....__") 'With "IU somewhere after "IS" and it's first 5 numbers.
If l_iIULocation = 0 Then
TranslateDranowebsString = "!!Error!! - Does not contain 'IU' followed by a number"
GoTo end_function
End If
l_strDElement = Mid(p_strIn, 4, l_iISLocation - 4) 'It's the data between the 4th character and the "IS"
l_strSElement = Mid(p_strIn, l_iISLocation + 5, l_iIULocation - l_iISLocation - 5) 'correct for the length of "IU"
l_strUElement = Mid(p_strIn, l_iIULocation + 5, Len(p_strIn) - (2 + 4 + l_iIULocation)) 'correct for the length of "IU" and "I"
If Len(l_strDElement) Mod 5 <> 0 Or Len(l_strSElement) Mod 25 <> 0 Or Len(l_strUElement) Mod 25 <> 0 Then
TranslateDranowebsString = "!!Error!! - There don't seem to be enough numbers in the string"
GoTo end_function
End If
l_strOut = "D Element: " + TranslateDranowebsNumberStrings(l_strDElement) + vbCrLf
l_strOut = l_strOut + "S Element: " + TranslateDranowebsNumberStrings(l_strSElement) + vbCrLf
l_strOut = l_strOut + "U Element: " + TranslateDranowebsNumberStrings(l_strUElement)
TranslateDranowebsString = l_strOut
End If
end_function:
End Function
Function TranslateDranowebsNumberStrings(p_strIn As String) As String
Dim l_strOut As String
Dim l_strThisChar As String
Dim i As Integer
'Debug.Print p_strIn
For i = 1 To Len(p_strIn) Step 5
l_strThisChar = Mid(p_strIn, i, 5)
Select Case l_strThisChar
Case "_____"
l_strThisChar = "0"
Case "____."
l_strThisChar = "9"
Case "___.."
l_strThisChar = "8"
Case "__..."
l_strThisChar = "7"
Case Else
l_strThisChar = "!!Error - " + l_strThisChar + "!!"
End Select
l_strOut = l_strOut + l_strThisChar
Next
'Debug.Print l_strOut
TranslateDranowebsNumberStrings = l_strOut
End Function
Ok... this certainly turned into a complex topic in a hurry.
The number of 45 may be incorrect, as I based this on an average count of morse characters, on the few "packets" I have been able to translate manually.
45 represented morse characters, and they are 21 real characters.
The strings I have are many, many end to end "detections" (transmitted packets).
As this system, if you can call it that, was not my own design, I know only what was explaind to me by it's designer, while detailed there may be some issues with the information.
I have been dumped with the task of making the dat ausable again, as the original receiver, did not register gaps at the desired interval, in addition there were occasional dropouts, and the receiving software failed to delimiate this also.
I have a suspiscion that there may be another character inserted at regular intervals as a time code of some sort.
The units produce only 10 states at a maximum, so theoretically, only those 10 number combinations listed on page one of this post are actually used.
This chunk came in while unit "number 3" was the only one in operation. A patchy day and I beleive a few dropouts. This is one that has not delimiated properly, and I'm in the process of manually translating it.
When I first made the post, I didn't have the whole story myself.
I simply had a pile of data thrown at me and given the task of interpreting it.
I would point out that replies here are optional, and if one finds this topic irritating, that they are under no obligation to reply.
My original post was to do with how to handle a string in a particular way. This question was answered exceptionally well - and I thank all who contributed.
the applications and actual data involved in this project could be also considered sensitive, and hence I am instructed to reveal only what is necessary to resolve the issues that I am experiencing.
As you may be aware, the internet connects a great variety of different people and places. If data security is an issue, one cannot make it's encryption technique public.
I understand the disappointment in the futility that some of you may feel, and I can only apologize for that. However, I have been instructed to redesign the system altogether.
This situation is equally frustrating for myself, this also limits the time for a perfect solution. I now have (with the help of contributors here) a solution that "works" in an adequate fashion, enough to solve the immediate issues.
Once again, the help and advice is HIGHLY appreciated, please do not think otherwise.
I know this is an old thread, but i just crossed paths with it in search of ther more pressing matters. Just wanted to take the time to thank everyone who posted. You all put in considerable time it seems, and it did help me resolve my issues in the end.