I don't know why, but when I need to code something ugly and quickly, I use VB6. When I need to parse lines, I use String functions instead of regexps. I tell myself it's because it's hard to anticipate how flawed, complicated regexps might work. This is true. Not a good excuse, but it's true. regexps can be difficult to debug.

Still, there's something I freakin' always screw up, and that's finding a substring in a line and cutting it into two. So here's some code for idiots that are me.

    Dim strTest As String
Dim strToFind As String

strTest = "this is a long line of words"
strToFind = "long"

Debug.Print "#" & InStr(strTest, strToFind) & "#"
Debug.Print "#" & Left(strTest, InStr(strTest, strToFind)) & "#"
Debug.Print "#" & Right(strTest, Len(strTest) - InStr(strTest, strToFind)) & "#"
Debug.Print "#" & Left(strTest, InStr(strTest, strToFind) - 1) & "#"
Debug.Print "#" & Right(strTest, Len(strTest) - (InStr(strTest, strToFind) + Len(strToFind))) & "#"

Here's our result:
#this is a l#
#ong line of words#

#this is a #
#line of words#

I don't know why, but I get more OBO errors doing this than I can stand.

Now playing: The Black Crowes - Cursed Diamond

Labels: ,