Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,933 questions

51,870 answers

573 users

How to check if a string contains only unique characters in VB.NET

2 Answers

0 votes
Imports System
				
Public Module Module1
	public function contains_unique_chars(s As String) As boolean
        Dim arr() As Char = s.ToCharArray

        Array.Sort(arr)
		
		For i As Integer = 0 to arr.Length - 2
			If arr(i) = arr(i + 1) Then
				return false 
			End If
		Next
	
        return true
	
	End Function 
	Public Sub Main()
		Dim s  As string = "abcde"
     
		If (contains_unique_chars(s)) Then
          	Console.Write("yes")
        else 
            Console.Write("no")
		End If
	End Sub
End Module



' run
'
' yes
'

 



answered Dec 29, 2019 by avibootz
0 votes
Imports System
         
Public Module Module1
	Public Function Sort_string(ByVal s As String) As String
        Dim arr() As Char = s.ToCharArray()
		
        Array.Sort(arr)
		
        Return New String(arr)
    End Function
    public function contains_unique_chars(s As String) As boolean
        s = Sort_string(s)
         
        For i As Integer = 0 to s.Length - 2
            If s(i) = s(i + 1) Then
                return false 
            End If
        Next
     
        return true
     
    End Function
    Public Sub Main()
        Dim s  As string = "abcde"
      
        If (contains_unique_chars(s)) Then
            Console.Write("yes")
        else 
            Console.Write("no")
        End If
    End Sub
End Module
 
 
 
' run
'
' yes
'

 



answered Dec 29, 2019 by avibootz
...