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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,693 questions

57,001 answers

573 users

How to find the smallest letter in a sorted array that is larger than a given letter in VB.NET

1 Answer

0 votes
Imports System

Class FindNextLetter
    Private Shared Function FindSmallestLetterGreaterThanTarget(ByVal letters As Char(), ByVal givenLetter As Char) As Char
        Dim left As Integer = 0
        Dim right As Integer = letters.Length - 1
        Dim result As Char = letters(0)

        While left <= right
            Dim mid As Integer = left + (right - left) / 2

            If letters(mid) > givenLetter Then
                result = letters(mid)
                right = mid - 1
            Else
                left = mid + 1
            End If
        End While

        Return result
    End Function

    Public Shared Sub Main()
        Dim letters As Char() = {"c"c, "e"c, "k"c, "m"c}
        Dim givenLetter As Char = "d"c
		
        Dim result As Char = FindSmallestLetterGreaterThanTarget(letters, givenLetter)
		
        Console.WriteLine($"The smallest letter greater than '{givenLetter}' is: {result}")
    End Sub
End Class


' run:
'
' The smallest letter greater than 'd' is: e
'

 



answered Sep 21, 2025 by avibootz
...