.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Display first unique character in the entered string

Posted By:Asha.MP       Posted Date: November 08, 2010    Points: 5    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

This code displays the first unique character in the entered string by the user.In this program there are no any builtin functions of.net like charAt(),IndexOf()and any string functions. Here only some controls like If, For.

Option Explicit On

Option Strict On

Public Class FirstCharCount

Shared Sub main()

Console.WriteLine("Enter string")

'Reading and saving the value in str variable

Dim str As String = Console.ReadLine()

'Declaring the array of type char

Dim chr(str.Length - 1) As Char

'Copying the characters from string to char array

For i = 0 To str.Length - 1

       chr(i) = str(i)


'Looping through the array of char

  For i = 0 To chr.Count - 1

  'Initializing the charCount for each char

        Dim charCount As Integer = 0

        'If char (i) in not nothing then only execute the comparision

        If chr(i) <> Nothing Then

                  For j = i + 1 To chr.Count - 1

                         'Comparing i'th char with J=i+1'th car

                         If chr(i) = chr(j) Then

                                'Incrementing the char count if chars are equal

                                 charCount += 1

                                 chr(j) = Nothing

                                 'If J reaches the end and there in no repeated count display that char

                          ElseIf j = chr.Count - 1 And charCount = 0 Then

                                    'Displaying the char

                                    Console.writeLine("First Unique character is:")



                                    'Exit after displaying the first unique char

                                     Exit Sub

                          End If


           End If


End Sub

End Class


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend