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 7498911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:38:12+00:00 2026-05-29T19:38:12+00:00

We have a master Person record and one (or more) duplicate Persons and we

  • 0

We have a master Person record and one (or more) duplicate Persons and we are merging their data, prioritising the master over the duplicate(s).

When it comes to phone numbers the goal is to merge their data, with a single phone number going into the Phone field and any other phone numbers going into a notes field (so as not to discard them completely). Records may or may not contain a phone number.

For neatness we don’t want to add to the notes field a bunch of numbers which are basically the same. So we don’t want the field to contain:

(1234) 123123
1234 123123

This would be easy if we could just discard the formatting and spaces but we need to retain those (except for white space on the beginning/end).

We started by creating a Structure (not sure why we have a Structure versus a Class, but anyway)

Friend Structure PhoneNumber

Private _Raw As String
Public Property Raw() As String
    Get
        Return _Raw
    End Get
    Set(ByVal value As String)
        _Raw = value
    End Set
End Property


Private _Stripped As String
Public Property Stripped() As String
    Get
        Return _Stripped
    End Get
    Set(ByVal value As String)
        _Stripped = value
    End Set
End Property


Sub New(ByVal num As String)
    Raw = num
    Dim RegexObj As New System.Text.RegularExpressions.Regex("[^\d]")
    Stripped = RegexObj.Replace(num, "")
    MsgBox(num & vbCrLf & Stripped)

End Sub
End Structure

Then, the merge code looks like this:

    Dim phones As New List(Of PhoneNumber)
    If master.Phone.Trim.Length > 1 Then
        phones.Add(New PhoneNumber(master.Phone.Trim))
    End If
    For Each x As Person In duplicates
        If x.Phone.Trim.Length > 1 And Not phones.Contains(New PhoneNumber(x.Phone.Trim)) Then
            phones.Add(New PhoneNumber(x.Phone.Trim))
        End If
    Next
    If phones.Count > 0 Then
        master.Phone = phones(0).Raw
    End If
    For i = 1 To phones.Count - 1
        master.Notes &= vbCrLf & "Alt. Phone: " & phones(i).Raw
    Next

But, obviously, the problem here is it’s allowing the duplicates.

We kind of want the Contains to match on “stripped” values only, but of course it doesn’t know to do that.

This already seems like too much code for such a minor feature, but at the moment we’re looking at writing something (in the Structure?) that will replace the Contains and match on stripped only. Is there a neater way?

Code is in VB, but C# answers welcome.

Remember too that we have to prioritise the master, so if we use LINQ and Distinct we need to ensure we don’t lose the sort order (that’s my understanding).

  • 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-05-29T19:38:13+00:00Added an answer on May 29, 2026 at 7:38 pm

    Figured out a better way to do this was to use a Dictionary. That way we can do without the Structure and use Dictionary lookups on both the Key (the stripped phone number) and the Value (the formatted original).

    Something like this:

        Dim RegexObj As New System.Text.RegularExpressions.Regex("[^\d]")
        Dim phones As New Dictionary(Of String, String)
        master.Phone = master.Phone.Trim
        If master.Phone.Length > 1 Then
            phones.Add(RegexObj.Replace(master.Phone, ""), master.Phone)
        End If
        For Each x As Person In duplicates
            x.Phone = x.Phone.Trim
            If x.Phone.Length > 1 And Not phones.ContainsKey(RegexObj.Replace(x.Phone, "")) Then
                phones.Add(RegexObj.Replace(x.Phone, ""), x.Phone)
            End If
        Next
        If phones.Count > 0 Then
            master.Phone = phones.First.Value
            phones.Remove(phones.First.Key)
        End If
        For Each entry As KeyValuePair(Of String, String) In phones
            master.Notes &= IIf(String.IsNullOrEmpty(master.Notes.Trim), "", vbCrLf).ToString _
                & "Alt. Phone: " & entry.Value
        Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one master page which applies to all pages in this website. On
I have a master record which I'd like to use with. Here's a very
Please see this pic: I have a one to many relationship between eg. Person
I have four classes. Class Person , and three more, Student , Professor ,
Do you think it may be OK for a person to have more than
I have 2 tables (entity) a person entity and a vacation entity. One person
I have a master table Person and a detail table Events I need to
I'm more a mysql person, but I have to do a db in pg
I'm a one-person IT department managing our company's website and recently recommended they have
I have a master detail relationship between a person and its friends: person id

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.