0

Is there a way to convert strings inside an array into lowercase?

So say I have an array like:

   String mainArray[] = {"Dog", "caT", "ElepHANT", "Hungry", "LION"}
   // So mainArray[0] = "Dog" mainArray[1] = "caT" etc.
   // So i get:
   mainArray[] = {"dog", "cat", "elephant", "hungry", "lion"}

Is there a function or method to iterate through the array and transform each string into lowercase?

Alex
  • 1
  • 1
  • 1
    There's no `String` type in the C++ standard library. Is this question mis-tagged? – Miles Budnek Sep 03 '17 at 03:56
  • I closed this as a duplicate, but do note that the *heavily upvoted* selected answer on that earlier question has a severe technical issue: the code has in general **Undefined Behavior**. Still, this is how SO works, that the readers decide what's good engineering, by voting on it. Never mind that voting is entirely inappropriate for engineering issues, as so very clearly exemplified here. – Cheers and hth. - Alf Sep 03 '17 at 04:02

1 Answers1

-3

Here's the answer try it:-

 String mainArray[] = {"Dog", "caT", "ElepHANT", "Hungry", "LION"};
        StringBuilder stringBuilder=new StringBuilder();
        for (String aMainArray : mainArray) {
            String lowerData = aMainArray.toLowerCase() + "\t";
            stringBuilder.append(lowerData);
        }
        System.out.print(stringBuilder);