Finding one one string in long list of other strings

  • Thread starter Thread starter Bob Johnson
  • Start date Start date
B

Bob Johnson

Using C#/2.0 I'm writing a small "data translator" utility app that reads
data out of a MS Access database and inserts it into a SQL Server database.
The source db lists a bunch of names of people (the particular table
structure is not relevant to this post). We need to identify the gender of
the people as best as we can. We currently have two text files
(MaleNames.txt and FemaleNames.txt) that list typically male or female
names, respectively. So "Scott" would be found in MaleNames.txt and "Julie"
would be found in FemaleNames.txt. There are hundreds of names in each
list/file. Of course some names like "Pat" and "Terry" could easily be
either - so are excluded from this translation process (names migrated, but
no sex specified).

My question:
I'd appreciate some suggestions for matching names with a gender "Male" or
"Female" - and do this matching in the C# utility app.

PCode for the end result I'm after would be something like this:

if (firstName [is in the list of MaleNames])
{
mySqlParm named "Gender" = "Male"
}
else
{
if (firstName [is in the list of FemaleNames])
{
mySqlParm named "Gender" = "Female"
}
else
{
mySqlParm named "Gender" = DBNull.Value
}
}

Thanks!
 
I would put all of the names in a dictionary and just do a lookup to see if
the name exists.

Cheers,

Greg
 
Read the textfiles in a string the string = stringMaleList.

if
(stringMaleList..IndexOf("Bob",0,"Bob".length,StringComparison.CurrentCultureIgnoreCase)
{
//In Malelist
}

Bob Johnson said:
Using C#/2.0 I'm writing a small "data translator" utility app that reads
data out of a MS Access database and inserts it into a SQL Server
database. The source db lists a bunch of names of people (the particular
table structure is not relevant to this post). We need to identify the
gender of the people as best as we can. We currently have two text files
(MaleNames.txt and FemaleNames.txt) that list typically male or female
names, respectively. So "Scott" would be found in MaleNames.txt and
"Julie" would be found in FemaleNames.txt. There are hundreds of names in
each list/file. Of course some names like "Pat" and "Terry" could easily
be either - so are excluded from this translation process (names migrated,
but no sex specified).

My question:
I'd appreciate some suggestions for matching names with a gender "Male" or
"Female" - and do this matching in the C# utility app.

PCode for the end result I'm after would be something like this:

if (firstName [is in the list of MaleNames])
{
mySqlParm named "Gender" = "Male"
}
else
{
if (firstName [is in the list of FemaleNames])
{
mySqlParm named "Gender" = "Female"
}
else
{
mySqlParm named "Gender" = DBNull.Value
}
}

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top