[AccessD] A2003:Replacing 'tokens' in a string

jwcolby jwcolby at colbyconsulting.com
Thu Jan 28 06:40:09 CST 2010


 > Yes John/Drew but why use that horrendous code when you can do the same with this..

The answer of course is that horrendous code is only horrendous code if you can't knock it out in 2 
minutes.  It takes me about 5 minutes longer to do a generic solution that can handle this same 
requirement than it takes you to do the one liner that only handles this one specific solution.

Why?  Because I am comfortable with classes.

How did I get that way?  By USING THEM!

;)

I actually USE a generic solution to this exact problem in many different places.  Having name / 
value strings like this is not something that was invented by the application under discussion, it 
is EVERYWHERE!  And it is often the case that you want to know not just the one value but every value.

So recode your one liner over and over if you wish.  I have a class pair in my framework that does 
this for me.

As for your "generic solution"... it does not handle key/value strings of variable length.  You have 
hard coded 0 to 3.  It does not handle getting a specific key value pair, it looks for a specific value.

You have gone to a lot of work for a solution that is good for exactly and only one specific 
instance, when 5 minutes more work would have handled the whole enchilada.

I call that lazy programming.  JMOOC.

Doing it the right way is so trivial an exercise that it seems incredible that you would argue the 
point.

John W. Colby
www.ColbyConsulting.com


Max Wanadoo wrote:
> Yes John/Drew but why use that horrendous code when you can do the same with
> this..
> 
> Call
> xsplit("[AccountNo]=1234,[InvoiceNo]=1234567,[InvoiceDate]=04/01/2010,[Name]
> =Barry")
> 
> Function xSplit(str as string)
>     Dim arr() As String, i As Integer
>     arr = Split(str, ",")
>     Debug.Print arr(0), arr(1), arr(2), arr(3) 'Done!
> 	'if you want the values then this next bit will do that
>     For i = 0 To 3
>         arr(i) = Mid(arr(i), InStr(arr(i), "=") + 1)
>         Debug.Print arr(i),
>     Next i
> End Function
> 
> A person cannot go through life taking the more obtuse form of coding just
> so that they may "learn" something new.
> It is all about getting the code out.
> I am with Stuart on  this.
> 
> Max




More information about the AccessD mailing list