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,885 questions

51,811 answers

573 users

How to get the indexes of words from an array of strings that start with a specific letter in VB.NET

2 Answers

0 votes
Imports System
Imports System.Collections.Generic
Imports System.Runtime.CompilerServices

Module Extensions
    <Extension()>
    Iterator Function IndexesWhere(Of T)(ByVal source As IEnumerable(Of T), ByVal predicate As Func(Of T, Boolean)) As IEnumerable(Of Integer)
        Dim index As Integer = 0

        For Each element As T In source
            If predicate(element) Then
                Yield index
            End If

            index += 1
        Next
    End Function
End Module

Public Class Program
    Public Shared Sub Main()
	    Dim s As String() = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "let’s start again"}
        
		Dim indexes = s.IndexesWhere(Function(t) t.StartsWith("t"))
        
		Console.Write(String.Join(", ", indexes))
    End Sub
End Class



' run:
'
' 2, 3, 10
'

 



answered Mar 13, 2025 by avibootz
0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
    Public Shared Function getIndexes(ByVal s As String()) As List(Of Integer)
        Dim indexes As List(Of Integer) = New List(Of Integer)()

        For i As Integer = 0 To s.Length - 1
            If s(i)(0) = "t"c Then
                indexes.Add(i)
            End If
        Next

        Return indexes
    End Function

    Public Shared Sub Main()
        Dim s As String() = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "let’s start again"}
	
        Dim indexes As List(Of Integer) = getIndexes(s)
        
	Console.Write(String.Join(", ", indexes))
    End Sub
End Class



' run:
'
' 2, 3, 10
'

 



answered Mar 13, 2025 by avibootz
...