I’ve got a textarea that I’m using for multi-line input. I’m feeding the textarea contents into an array for later parsing. Sometimes, but not always, the data pasted into the textarea has leading spaces. I’m populating the array with the following code - what’s a good way to run a Trim while doing this, all together?
// Use better variable names for clarity in the future!
dim arsInputLines() as String = InputArray
for i as Integer = 0 to arsInputLines.Ubound
arsInputLines(i) = trim(arsInputLines(i))
next
If you expect a lot of lines, then store the Ubound as a variable first so it doesn’t have to get counted again and again.
dim rxTrim as new RegEx
rxTrim.SearchPattern = "(?mi-Us)^[\\x20\\t]*(.*\\S)?[\\x20\\t]*$"
rxTrim.ReplacementPattern = "$1"
rxTrim.Options.ReplaceAllMatches = true
dim s as string = rxTrim.Replace( inputString )
Edit: Added the “?” to take care of lines that are only whitespace.
It was a light-hearted stab at your variable naming. It’s not a necessary step.
But yes, my method iterates through each element to the array and trims them individually. This makes it so every line is trimmed.