Solved

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

Posted on 2015-01-29
7
955 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 63

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 86

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 63

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

631 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