Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 2.06 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Neatest way to get a distinct list of phone numbers (without removing original formatting)?
  2. Friend Structure PhoneNumber
  3.  
  4. Private _Raw As String
  5. Public Property Raw() As String
  6.     Get
  7.         Return _Raw
  8.     End Get
  9.     Set(ByVal value As String)
  10.         _Raw = value
  11.     End Set
  12. End Property
  13.  
  14.  
  15. Private _Stripped As String
  16. Public Property Stripped() As String
  17.     Get
  18.         Return _Stripped
  19.     End Get
  20.     Set(ByVal value As String)
  21.         _Stripped = value
  22.     End Set
  23. End Property
  24.  
  25.  
  26. Sub New(ByVal num As String)
  27.     Raw = num
  28.     Dim RegexObj As New System.Text.RegularExpressions.Regex("[^d]")
  29.     Stripped = RegexObj.Replace(num, "")
  30.     MsgBox(num & vbCrLf & Stripped)
  31.  
  32. End Sub
  33. End Structure
  34.        
  35. Dim phones As New List(Of PhoneNumber)
  36.     If master.Phone.Trim.Length > 1 Then
  37.         phones.Add(New PhoneNumber(master.Phone.Trim))
  38.     End If
  39.     For Each x As Person In duplicates
  40.         If x.Phone.Trim.Length > 1 And Not phones.Contains(New PhoneNumber(x.Phone.Trim)) Then
  41.             phones.Add(New PhoneNumber(x.Phone.Trim))
  42.         End If
  43.     Next
  44.     If phones.Count > 0 Then
  45.         master.Phone = phones(0).Raw
  46.     End If
  47.     For i = 1 To phones.Count - 1
  48.         master.Notes &= vbCrLf & "Alt. Phone: " & phones(i).Raw
  49.     Next
  50.        
  51. Dim RegexObj As New System.Text.RegularExpressions.Regex("[^d]")
  52.     Dim phones As New Dictionary(Of String, String)
  53.     master.Phone = master.Phone.Trim
  54.     If master.Phone.Length > 1 Then
  55.         phones.Add(RegexObj.Replace(master.Phone, ""), master.Phone)
  56.     End If
  57.     For Each x As Person In duplicates
  58.         x.Phone = x.Phone.Trim
  59.         If x.Phone.Length > 1 And Not phones.ContainsKey(RegexObj.Replace(x.Phone, "")) Then
  60.             phones.Add(RegexObj.Replace(x.Phone, ""), x.Phone)
  61.         End If
  62.     Next
  63.     If phones.Count > 0 Then
  64.         master.Phone = phones.First.Value
  65.         phones.Remove(phones.First.Key)
  66.     End If
  67.     For Each entry As KeyValuePair(Of String, String) In phones
  68.         master.Notes &= IIf(String.IsNullOrEmpty(master.Notes.Trim), "", vbCrLf).ToString _
  69.             & "Alt. Phone: " & entry.Value
  70.     Next