Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string array to lowercase

Tags:

arrays

string

c#

I have string array string[] MyArray. What is the quickest (meaning least code, not fastest performance) way to convert all string array elements to lowercase?

like image 385
Tomas Avatar asked May 30 '11 13:05

Tomas


People also ask

How do you convert a string array to lowercase?

To convert all array elements to lowercase:Use the map() method to iterate over the array. On each iteration, call the toLowerCase() method to convert the string to lowercase and return the result. The map method will return a new array containing only lowercase strings.

How do you make a string array lowercase in Java?

toLowerCase(). split(",");

How do I convert a string to lowercase?

Java String toLowerCase() Method The toLowerCase() method converts a string to lower case letters. Note: The toUpperCase() method converts a string to upper case letters.


2 Answers

var MyArrayLower = MyArray.Select(s => s.ToLowerInvariant()).ToArray(); 

(or

MyArray = MyArray.Select(s => s.ToLowerInvariant()).ToArray(); 

if you want to replace the existing array with a new instance of string[].)

like image 147
jason Avatar answered Sep 23 '22 08:09

jason


Easiest approach:

MyArray = Array.ConvertAll(MyArray, d => d.ToLower()); 
like image 31
prasadd Avatar answered Sep 24 '22 08:09

prasadd