[AccessD] formatting strings and placing them in a larger str ing

Arthur Fuller artful at rogers.com
Wed Aug 11 14:27:19 CDT 2004


I used a technique a while ago which you might find useful. I just came
up with it myself and didn't carefully guard against unusual situations,
since there weren't any. If your text has unusual possibilities, you may
need to revise this accordingly. Provisos aside, I came up with a
convention like this (this is pseudo-code, no wrap etc.)

strTarget = "This is a string containing markers such as
\\InvoiceNumber\\ and further along in the string another marker, this
one named \\Quantity\\ and yet another named \\Price\\.

lngInvoiceNo = 12345
intQty = 23
currPrice = 2999.99

strTarget = Replace(strTarget,"\\InvoiceNumber\\",lngInvoiceNo)
strTarget = Replace(strTarget,"\\Quantity\\",intQty)
strTarget = Replace(strTarget,"\\Price\\",currPrice)

In the actual app in which I did this, there were about 2 dozen such
replaces going on. It took a second or two, but nothing to complain
about.

I did however have problems concerning the length of the string. I could
never nail down exactly when and why it would sometimes fail, but I
thing it had to do with the length of the string in question. I
eventually gave up inspecting it in the debugger and went another way. I
stored the target string in a database column instead of in the code,
then derived the "replacement" string using a temp table and a query.
For some reason, that approach worked infallibly while the simple
string-replace in memory gave me problems occasionally. Your mileage may
vary. Given the length of the string you want to build, go ahead and try
it in memory, but if you hit a bump in the road, consider the
stored-text approach.

HTH,
Arthur


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Colby, John
Sent: Wednesday, August 11, 2004 2:49 PM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] formatting strings and placing them in a larger
str ing


Cool, now I need to know how to place a string of len N at position O in
another string.

This is for export to a mainframe where the string they want is about
3,000 characters, of which a total of about 200 characters will actually
have data from us.

So:

Insert in a string of blanks (spaces), at position 12, a string of
length 10.  REPLACE 10 characters with my 10 characters, starting at
position 12. Insert in a string of blanks, at position 60, a string of
length 25. Insert in a string of blanks, at position 124, a string of
length 13.

Etc.

I have a field map of their data, and I can brute force it by just
appending strings together.  I think it was Gustav that suggested a
smarter way using a built in VB function.

JWC





More information about the AccessD mailing list