title:
Put the knife down and take a green herb, dude.

descrip:
One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com

Self-Pimpin':
Member of an email list?
You need The Digest Handler!!


FOR ENTERTAINMENT PURPOSES ONLY!!! Back-up your data and always wear white.
URLs I want to remember:
* Atari 2600 programming on your Mac
* joel on software (tip pt)
* resume, mostly for Google * Regular Expression Introduction (copy)
* gpl xbrowser API for dhtml
* mulder (old css tutorial)
* Using CommonDialog in VB 6 * Free zip utils
* that hardware vendor review site I forget about is here * Javascript 1.5 ref
* Read the bits about the zone * w3c.org index of HTML 4.01 elements
* Mozilla COM control * Quick intro to Javascript
* Editable Firefox Page * Parsing str's in VB6
email if ya gotta, RSS if ya wanna RSS
 
 
Thursday, December 04, 2008

Parsing strings in VB 6

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
Debug.Print "#" & Left(strTest, InStr(strTest, strToFind) - 1) & "#"
Debug.Print "#" & Right(strTest, Len(strTest) - (InStr(strTest, strToFind) + Len(strToFind))) & "#"


Here's our result:
#11#
#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: ,


posted by ruffin at 12/04/2008 11:52:00 PM
0 comments




Powered by Blogger furthurnet.org