Skip to sidebar Skip to content
Ipercube Technical
Jack of all trades, master of none
Date: Time: - Stardate:
Welcome, Log in by clicking  Here!
SS64
MDN
Stack
Code
GitHub
Wiki
Convert
V Studio
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions
Ipercube Technical
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions

Convert Domain Format

Converts a domain between DN format and DNS format based on the direction parameter.

Conversion direction can be “DnToDns” or “DnsToDn“.

VB
    Public Function ConvertDomainFormat(domain As String, 
                                        direction As String) As String
                                        
        If String.IsNullOrEmpty(domain) Then
            Throw New ArgumentException("Domain cannot be null or empty.")
        End If

        If String.IsNullOrEmpty(direction) Then
            Throw New ArgumentException("Direction parameter cannot be null or empty.")
        End If

        direction = direction.Trim().ToLower()

        If direction = "dntodns" Then
            ' Convert from DN to DNS
            Dim parts() As String = domain.Split(","c)
            Dim dnsParts As New List(Of String)()

            For Each part As String In parts
                Dim trimmedPart As String = part.Trim()
                If trimmedPart.StartsWith("DC=", StringComparison.OrdinalIgnoreCase) Then
                    Dim dcValue As String = trimmedPart.Substring(3)
                    dnsParts.Add(dcValue)
                End If
            Next

            Return String.Join(".", dnsParts)
            
        ElseIf direction = "dnstodn" Then
            ' Convert from DNS to DN
            Dim dnsParts() As String = domain.Split("."c)
            Dim dnParts As New List(Of String)()

            For Each part As String In dnsParts
                dnParts.Add("DC=" & part)
            Next

            Return String.Join(",", dnParts)
        Else
            Throw New ArgumentException("Invalid direction parameter. Use 'DnToDns' or 'DnsToDn'.")
        End If
    End Function
Posted by ipercube


© 2026 Ipercube Design