Solved

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

Posted on 2015-01-29
7
560 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Deserialize JSON array VB.Net problem 3 38
Encryption Decryption in Oracle 12 65
Convert string to date 3 40
Close word object 13 24
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

15 Experts available now in Live!

Get 1:1 Help Now