Iterating over the characters in a string

Iterating over the characters in a string

Visual Basic .NET strings support the For Each statement, so you can iterate over each individual character as follows:

Dim s As String = "ABCDE"Dim c As CharFor Each c In s    Console.Write(c & ".")       ' => A.B.C.D.E.Next

However, you should bear in mind that For Each loops on string characters aren’t optimized. The following solution, that uses the Chars property, is 2-5 times faster:

Dim i As IntegerFor i = 0 To s.Length - 1    Console.Write(s.Chars(i) & ".")       ' => A.B.C.D.E.Next

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular