Solved

How do I convert an array of String to UpperCase in VB.net?

Posted on 2015-01-29
7
598 Views
Last Modified: 2016-02-16
Hi:

I have an array of strings declared in vb.net

Dim someStrings() as String

Open in new window


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?
0
Comment
Question by:jxbma
7 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 40578742
How about something like this (not using LINQ):

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.)
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 40578750
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

Open in new window

0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40578842
Hi  jxbma;

To your question, "Is there a way I can elegantly convert the entire array to upper case using a LINQ query?", here you go.

Dim isNowUpper() As String = (From s As String In someStrings
                              Select s.ToUpper).ToArray()

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 21

Expert Comment

by:masterpass
ID: 40578872
or something like this:

Dim someStrings() As String = {"aaa", "bbb", "ccc"}
Dim upperArray = someStrings.Select(Function(s) s.ToUpper()).ToArray()

Open in new window


HTH :)
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40579030
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)

Open in new window

0
 
LVL 1

Author Closing Comment

by:jxbma
ID: 40582052
This is the solution I chose to go with. Thx!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40582056
Not a problem jxbma, glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now