jxbma
asked on
How do I convert an array of String to UpperCase in VB.net?
Hi:
I have an array of strings declared in vb.net
I now I could do a for loop and convert each member of the array to uppercase.
Is there a way I can elegantly convert the entire array to upper case using a LINQ query?
I have an array of strings declared in vb.net
Dim someStrings() as String
I now I could do a for loop and convert each member of the array to uppercase.
Is there a way I can elegantly convert the entire array to upper case using a LINQ query?
Here's a VBA version that works, although there are improvements in VB.Net (which I can check when I get home if the above doesn't quite work):
Sub x()
Dim someStrings() As String
ReDim someStrings(3)
someStrings(0) = "kljdsklgjjkenrgh"
someStrings(1) = ".dklsjgkldjklgdf"
someStrings(2) = ".dsjfkldfsjkldfs"
someStrings(3) = ". kldjfkldjs"
Dim strAll As String
strAll = UCase(Join(someStrings, "~"))
someStrings = Split(strAll, "~")
MsgBox someStrings(3)
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or something like this:
HTH :)
Dim someStrings() As String = {"aaa", "bbb", "ccc"}
Dim upperArray = someStrings.Select(Function(s) s.ToUpper()).ToArray()
HTH :)
Here's a clean non-LINQ approach:
Dim someStrings() As String = {"cat", "dog", "fish"}
someStrings = Array.ConvertAll(Of String, String)(someStrings, Function(s) s.ToUpper)
ASKER
This is the solution I chose to go with. Thx!
Not a problem jxbma, glad to help.
Dim strAll As String = Join(someStrings, "~")
strAll.toUpperCase()
someStrings = strAll.split("~")
(I'm not sure if the syntax is quite right, but it should be close, and could probably all be done in one line.)