473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Replace text in a field?

Jim
Hey all, I have a dilemma.

I have a field in a table called "Supervisor." The table currently
has 1,500+ records. Sometimes, the HR download that populates the
field formats the field one way, sometimes another. For example, I
may get records such as follows:

Supervisor
Hall,John J.
Hall, John J
Harrison, Marcie
Harrison,Marcie

So you see, sometimes there is a space after the comma, sometimes not.
Because additional data is uploaded weekly, I'll need to create some
code that runs through the list and changes them all to have spaces
following the comma. How do I fix this using code?

Thanks
Nov 12 '05 #1
3 3528
On 15 Dec 2003 19:10:35 -0800, ji*************@hotmail.com (Jim)
wrote:

What do you have so far?
-Tom.

Hey all, I have a dilemma.

I have a field in a table called "Supervisor." The table currently
has 1,500+ records. Sometimes, the HR download that populates the
field formats the field one way, sometimes another. For example, I
may get records such as follows:

Supervisor
Hall,John J.
Hall, John J
Harrison, Marcie
Harrison,Marcie

So you see, sometimes there is a space after the comma, sometimes not.
Because additional data is uploaded weekly, I'll need to create some
code that runs through the list and changes them all to have spaces
following the comma. How do I fix this using code?

Thanks


Nov 12 '05 #2
>> Hey all, I have a dilemma.

I have a field in a table called "Supervisor." The table currently
has 1,500+ records. Sometimes, the HR download that populates the
field formats the field one way, sometimes another. For example, I
may get records such as follows:

Supervisor
Hall,John J.
Hall, John J
Harrison, Marcie
Harrison,Marcie

So you see, sometimes there is a space after the comma, sometimes not.
Because additional data is uploaded weekly, I'll need to create some
code that runs through the list and changes them all to have spaces
following the comma. How do I fix this using code?


This is a commen problem and there are many algorithms around that'll
accomplish this task (with varying degrees of success).

The best way is to find a way around it. Could HR interact with the main
DB to search for a person before adding/modifying? Your essentially
matching records based on a text field, which is never good :)

However, it is sometimes unavoidable.. a couple of algorithms come to
mind, one is Soundex which matches strings based on the way they sound.
You create (and probably best to store it with each record) a soundex
key.. as new records come in, compute their soundex key and compare. Do
some searching on "soundex" and you'll find many examples written in
VB/VBA.. it's not a lot of code to accomplish it.

in your case where punctuation is a bigger concern, there is another
algorithm; "levenshtein length" - I believe the idea here is (and I could
be mistaken) to take two strings and score them based on how many
characters must be changed to make them equal. This would certainly catch
the examples you provided if you considered cases of levenshtein length
beings less than 2 as a threshold to be equal.

so, use that as a starting point in your search;
soundex
levenshtein length

good luck!

--
email: my*****@canada.com // my_nick = mork
Nov 12 '05 #3
>> Supervisor
Hall,John J.
Hall, John J
Harrison, Marcie
Harrison,Marcie

So you see, sometimes there is a space after the comma, sometimes not.
Because additional data is uploaded weekly, I'll need to create some
code that runs through the list and changes them all to have spaces
following the comma. How do I fix this using code?


Sorry, I may have misunderstood your objective in my last post. I thought
you were bringing in records and wanted to find matching redcords based on
the name. If it's simply straightening up the format of the name you
seek, then doing some string manipulation is what you seek.

A regular expression would do the trick, of course, but you could do
something like replace all occurences of "comma followed by a space" with
"comma", then replace all occurences of "comma" with "comma followed by a
space"..

you'll need to do suqash it down to just comma's first to avoid ending up
with "Hall, John J" (note: 2 spaces). This can eb done in one line

strNameAfter = Replace(Replace(strNameBefore, ", ", ","), ",", ", ")

So, here's something I just tried and it seems to work for the examples
you provided:

Dim inNames As Variant
Dim outName As String

inNames = Array("Hall,John J.", _
"Hall, John J.", _
"Harrison, Marcie", _
"Harrison,Marcie")

For Each strName In inNames
outName = Replace(Replace(strName, ", ", ","), ",", ", ")
debug.print outName
Next strName

Output:
-------
Hall, John J.
Hall, John J.
Harrison, Marcie
Harrison, Marcie
is this what you were after? Hope it helps!

--
email: my*****@canada.com // my_nick = mork
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Craig Keightley | last post by:
Can these lines of sql statements be consolidated into one sql statement (possibly using reg exps??) BEGIN CODE ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Update...
6
by: bateman | last post by:
Hi, what I am trying to do is the following, its causing some probs though: I have the following in a database: ] This is just some dummy text. It doesn't mean anything and is for placeholding...
2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
2
by: jason | last post by:
Hello. I just converted some data to to sql2000 into a TEXT type field. I needed to remove all tabs from the data and now want to remove extra lines too. As we know, SQL2000's replace function...
5
by: djc | last post by:
I need to prepare a large text database field to display in an asp.net repeater control. Currently I am replacing all chr(13)'s with a "<br/>" and it works fine. However, now I also want to be able...
3
by: jmarr02s | last post by:
Hi, How do I replace with when the field is empty? Thanks! jmarr02s
9
by: MrHelpMe | last post by:
Hello again experts, I have successfully pulled data from an LDAP server and now what I want to do is drop the data into a database table. The following is my code that will insert the data but...
2
by: john | last post by:
In a table I have text field A. I would like to replace all the null values in field A to a real value, let's say 'Test'. When I use Find & Replace and I search for 'is null' and I press replace or...
14
by: Adrienne Boswell | last post by:
Although this is a client side issue, I am also posting to asp.general in case there is someway to do this only server side (which I would prefer). Here's my form: <form method="post"...
6
by: simon.robin.jackson | last post by:
Ok. I need to develop a macro/vba code to do the following. There are at least 300 corrections and its expected for this to happen a lot more in the future. Therefore id like a nice...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.