Hey folks, me again. This time I have a simple problem and the solution I went with, as usual, feels like a slow, dirty hack. I've mucked about a bit with Regex for a more efficient solution, but I'm not terribly bright so I haven't made a lot of progress. What I'm doing is looking for instances of multiple consecutive spaces in a string (there can be anywhere from 2 to 8) and replacing them with a single space, then splitting the string using Space as a delimiter. The super awesome method I'm using to crunch down multiple spaces is this:
With this method, I need to iterate through my string multiple times, because if there are 3 or more spaces in a row, replacing pairs with singles will create additional pairs, that need to be stripped out again. Eventually, all the pairs will be stripped and I'll have my single spaced string, but this feels like a crap way to do it. I'd really like to be able to process the string in a single pass.
Any thoughts?
Do Until Not strLineIn Like "* *" strLineIn = strLineIn.Replace(" ", " ") Loop
With this method, I need to iterate through my string multiple times, because if there are 3 or more spaces in a row, replacing pairs with singles will create additional pairs, that need to be stripped out again. Eventually, all the pairs will be stripped and I'll have my single spaced string, but this feels like a crap way to do it. I'd really like to be able to process the string in a single pass.
Any thoughts?