BrI
02-19-2019, 10:20 AM
I'm pulling ID numbers from a text string using the split function.
The problem is that the original string source is from a scanned document and sometimes the characters were incorrectly converted to text.
The full correct string preceding the ID I want to extract is "CarID(s):". In the example below a "~" character is where a "s" should be, I used error handling below to illustrate. This works for this specific case, but of course would not be a solution as would not know what the error would be before running the code.
As long as a primary portion of the string was intact, say "CarID", is there a method that could be used to accommodate variations in the rest of text?
On Error Resume Next
CarID = Trim(Split(Split(strText, "CarID(s):")(1), vbCrLf)(0)) 'CarID(s) - Correct
CarID = Trim(Split(Split(strText, "CarID(~):")(1), vbCrLf)(0)) 'CarID(~) - Incorrect
On Error GoTo 0
The problem is that the original string source is from a scanned document and sometimes the characters were incorrectly converted to text.
The full correct string preceding the ID I want to extract is "CarID(s):". In the example below a "~" character is where a "s" should be, I used error handling below to illustrate. This works for this specific case, but of course would not be a solution as would not know what the error would be before running the code.
As long as a primary portion of the string was intact, say "CarID", is there a method that could be used to accommodate variations in the rest of text?
On Error Resume Next
CarID = Trim(Split(Split(strText, "CarID(s):")(1), vbCrLf)(0)) 'CarID(s) - Correct
CarID = Trim(Split(Split(strText, "CarID(~):")(1), vbCrLf)(0)) 'CarID(~) - Incorrect
On Error GoTo 0