Get the first character of string using VB.NET
string, vb.net, winforms
Solution
The easiest is using LINQ:
Dim firstChar = str.First()
Dim lastChar = str.Last()
You can use LINQ since a `String` is also an `IEnumerable(Of Char)` implicitely.
- `Enumerable.First Method`
- `Enumerable.Last Method`
You can also use it like a `Char-Array`(`String.Chars` is the default property) and access the first and last char via index:
firstChar = str(0)
lastChar = str(str.Length - 1)
Problem
Let’s say that my string is: ``` test! ``` I want to get the first character t est! Also I want to get the last character test `!` How can I do that?