For Example : String = Visual BasiC output = V C
I have tried searching everywhere but found none, is it possible for vb.net to do this one?
For Example : String = Visual BasiC output = V C
I have tried searching everywhere but found none, is it possible for vb.net to do this one?
The following code iterates forward through the string until it finds a capital letter, adds that to the result and exits the first loop. It then iterates backwards through the string until it finds a capital letter, adds it to the result and exits the loop. Finally, it returns the result to the calling code.
I suspect that this is a school/college assignment, so I would suggest that you read Open letter to Students with homework problems
Private Function FirstAndLastCapitalLetter(s As String) As String
Dim result As String = ""
For i As Integer = 0 To s.Length - 1
If s.Substring(i, 1) = s.Substring(i, 1).ToUpper Then
result = result & s.Substring(i, 1)
Exit For
End If
Next
For i As Integer = s.Length - 1 To 0 Step -1
If s.Substring(i, 1) = s.Substring(i, 1).ToUpper Then
result = result & s.Substring(i, 1)
Exit For
End If
Next
Return result
End Function