Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8115241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:24:21+00:00 2026-06-06T03:24:21+00:00

I have written this function to auto correct gender to M or F from

  • 0

I have written this function to auto correct gender to M or F from different values in a string array. It works fine but my manager told me to use Dictionary which he said is more efficient. But I have no idea. Anyone like to help me to understand how this can be done ? Thanks.

    Public Function AutoGender(ByVal dt As DataTable) As DataTable        

    Dim Gender As String = ""
    Dim Mkeywords() As String = {"boy", "boys", "male", "man", "m", "men", "guy"}
    Dim Fkeywords() As String = {"girl", "girls", "female", "woman", "f", "women", "chick"}
    Dim row As DataRow
        For Each row In dt.Rows
            If Mkeywords.Contains(row("Gender").ToString.ToLower) Then
                Gender = "M"
                row("Gender") = Gender
            ElseIf Fkeywords.Contains(row("Gender").ToString.ToLower) Then
                Gender = "F"
                row("Gender") = Gender
            End If
        Next
    Return dt

    End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:24:24+00:00Added an answer on June 6, 2026 at 3:24 am

    Here is an example how you could implement the Dictionary(Of String, String) to lookup whether this synonym is known or not:

    Shared GenderSynonyms As Dictionary(Of String, String) = New Dictionary(Of String, String) From
        {{"boy", "M"}, {"boys", "M"}, {"male", "M"}, {"man", "M"}, {"m", "M"}, {"men", "M"}, {"guy", "M"},
         {"girl", "F"}, {"girls", "F"}, {"female", "F"}, {"woman", "F"}, {"f", "F"}, {"women", "F"}, {"chick", "F"}}
    
    Public Function AutoGender(ByVal dt As DataTable) As DataTable
        If dt.Columns.Contains("Gender") Then
            For Each row As DataRow In dt.Rows
                Dim oldGender = row.Field(Of String)("Gender").ToLower
                Dim newGender As String = String.Empty
                If GenderSynonyms.TryGetValue(oldGender, newGender) Then
                    row.SetField("Gender", newGender)
                End If
            Next
        End If
        Return dt
    End Function
    

    Note that i’ve used the collection initializer to fill the Dictionary that is a convenient way to use literals to initialize collections. You could also use the Add method.

    Edit: Just another approach that might be more concise is using two HashSet(Of String), one for the male synonyms and one for the female:

    Shared maleSynonyms As New HashSet(Of String) From
        {"boy", "boys", "male", "man", "m", "men", "guy"}
    Shared femaleSynonyms As New HashSet(Of String) From
        {"girl", "girls", "female", "woman", "f", "women", "chick"}
    
    Public Function AutoGender(ByVal dt As DataTable) As DataTable
        If dt.Columns.Contains("Gender") Then
            For Each row As DataRow In dt.Rows
                Dim oldGender = row.Field(Of String)("Gender").ToLower
                Dim newGender As String = String.Empty
                If maleSynonyms.Contains(oldGender) Then
                    row.SetField("Gender", "M")
                ElseIf femaleSynonyms.Contains(oldGender) Then
                    row.SetField("Gender", "F")
                End If
            Next
        End If
        Return dt
    End Function
    

    A HashSet must also be unique, so it cannot contain duplicate Strings (like the key in the Dictionary), but it’s not a key-value pair but only a set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function to print database table to an array like this
I have written this function in SQL and I can't figure out why but
I have written this function to calculate the average of some floats.But it has
I have written my own function, which in C would be declared like this,
I have written a function for deleting object preiodically. function add(variable, expireSecond){ this.list[variable] =
I have written this code to convert string in such format 0(532) 222 22
I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,
In my code I have written this but it fails to compile: In Class1.h:
A template function I have written has the following signature: template<class IteratorT> auto average(IteratorT&
I have written this function in C: void *PWNRetain(void *object) { PWNObject *obj =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.