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

jwcolby jwcolby at colbyconsulting.com
Tue Jan 26 21:38:53 CST 2010


I would suggest breaking the problem down into parts.  The "format" is identical (which makes this 
easy):

"
[
Variable Name
]
=
Variable Value
"
,


So go get the position of the second quote.  Instr allows you to look for something starting at 
position X.  Start at position 2 and look for the "

Having that position, get everything LEFT of that into a string variable.  I will call this a 
"TOKEN" and this process "Parsing the token".

Use Replace() to get rid of that Token you just captured from the big string.

In the TOKEN, get the piece between [ and ] and place that in strName

In the TOKEN, get the piece to the right of the = and place that in strValue

Now you have a variable name and a variable value.

Is the variable name what you are looking for?  If yes you are done, else parse the next token.

Repeat until the name is found or the big string is empty.

BTW, this is a very good use for classes.  clsToken is used to store the Name and Value and hold the 
code for finding the Name and Value inside of the token.  clsTokenParse contains a collection to 
store the clsToken instances and contains code used to parse the tokens and create clsToken instances.

When you are done, you have a clsTokenParse with a collection full of clsToken instances, and those 
can be used as you need.

By the way, this concept is what I used in my OpenArgs demo.

http://www.databaseadvisors.com/downloads.asp

Second item down.

This demo does EXACTLY what I discussed above except the "format" is:

Variable Name
=
Variable Value
;



John W. Colby
www.ColbyConsulting.com


Darren - Active Billing wrote:
> Hi team
> 
> Assuming the string below
> 
> "[AccountNo]=1234","[InvoiceNo]=1234567","[InvoiceDate]=04/01/2010","[Name]=
> Barry"
> 
> How would I get just the Invoice Number bit = Eg 1234567?
> 
> The 'token' [InvoiceNo] will be constant followed by an "=" sign
> 
> But sadly the position of the [InvoiceNo] token in the string will not be
> constant - Otherwise I'd just use MID()
> 
> Nor will the length of the invoice number - Some may be 4 digits others 6
> etc
> 
> I need to pull just the Invoice Number (And the Account Number) out of the
> string to build a new string being used elsewhere
> 
> Many thanks in advance
> 
> Darren
> 
>  
> 



More information about the AccessD mailing list