I want to trim and convert all the string elements in an array to lowercase without using for each loop. Can someone help me with this?
Example :
varStrArray={“Ha Rs ha”, “Te Am”}
Expected output:
varStrArray={“harsha”, “team”}
I want to trim and convert all the string elements in an array to lowercase without using for each loop. Can someone help me with this?
Example :
varStrArray={“Ha Rs ha”, “Te Am”}
Expected output:
varStrArray={“harsha”, “team”}
Why not just use For Each? Simple and effective.
I may have 100’s of string elements in that array, so i don’t want to Loop through all of them. Instead i am thinking if we can do it using any method or linq or something else.
arrNew = varStrArray.Select(Function (x) x.Replace(" ","").toLower).toArray
@ppr thank you so much!! This will help me for now. But in case if we have double or tripple space in the string, then what can be the condition? Because i may get those strings in the array which may have more spaces. So i want trim those strings dynamically.
Hundreds is nothing. I’ve done For Each tests with hundreds of thousands and millions of items. Linq still loops. It’s a myth that it’s automatically faster. Just use For Each. It’ll take milliseconds.
Replace will work on each occurring space
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.