Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need search & replace function to replace words w/abbreviations

Status
Not open for further replies.

Nevets

Technical User
Jul 23, 2001
27
US
Can anybody help me with a function to perform a search and replace for a string within a string (Access 97)?
I am working with tables containing book titles.
For reporting purposes, I need to search within the title for certain words and abbreviate them.
For example, if there were a book titled "Advanced Access 97" I would need it to appear a "Advd Acces 97".
Other examples are 'guide' = 'gde', 'guide to' = 'gt', etc., etc....
I have quite a long list of words which need to be abbreviated.
Many thanks in advance for any help!
 
seems easy enough.. something like this:

'post string being built
dim buildstring as string

'string being searched
dim searchstring as string

'string searching for
dim mystring as string

'string replacing mystring
dim replacementstring as string

dim leftpos as integer
dim rightpos as integer
dim mylength as integer

leftpos = instr(1,searchstring,mystring, 0)
rightpos = len(searchstring) - len(mystring) - leftpos
mylength = len(mystring)
buildstring = left(searchstring,leftpos) & replacementstring & right(searchstring, rightpos)


hope this helps.. Cruz'n and Booz'n always.
This post shows what little I do at work.
 
I'm not quite clear on where I would identify what words are to be abbreviated, and what their abbreviations would be.
Examples being:
Advanced = Advd
Illustrated = Illus
Cookbook = Ckbk

Where would this fit into the code?
Sorry if I'm being a bit dense... I am self taught in VBA, as well as suffering from end of the work week brain cramps.
 
please realize this isn't tested:

'post string being built
dim buildstring as string

'string being searched
dim searchstring as string

'string searching for
dim mystring as string

'string replacing mystring
dim replacementstring as string

dim leftpos as integer
dim rightpos as integer
dim numofab as integer 'number of abreviatoins.
dim i as integer

numofab=inputbox(prompt:="number of abbreviations", title:="abreviation")

for i = 0 to numofab step 1

mystring = inputbox(prompt:="enter string to be replaced, title:="String replacement")

replacementstring = inputbox(prompt:="enter abrv to be used for" & mystring, title:="replacement")

leftpos = instr(1,searchstring,mystring, 0)

rightpos = len(searchstring) - len(mystring) - leftpos
'removed mylength it served no purpose
buildstring = left(searchstring,leftpos) & replacementstring & right(searchstring, rightpos)
next i

try something like that...
this'll loop through for how many abbreviations you want to do, although it's annoying with the input boxes!

I'm leaving for the weekend, this is a quick suggestion, hopefully if you have more problems someone else can help you this weekend.. (i'll be back monday!)
Cruz'n and Booz'n always.
This post shows what little I do at work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top