View Single Post
  #2 (permalink)  
Old 12-02-2009, 01:23 PM
agraham's Avatar
agraham agraham is offline
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

There is no intrinsic String method in .NET that would do that so it will have to be synthesised and as they are String operations it is very nearly as efficient when optimised compiled Basic4ppc as when doing it in a library.
Code:
Sub MergeWhiteSpaces(str)
    str = StrReplace(str, 
Chr(8), " ")
    
Do
        Len1 = StrLength(str)
        str = StrReplace(str, 
"  "" "' replace two spaces by one
    Loop Until Len1 = StrLength(str)

    
Return str
End Sub
You could also use a StringBuilder, iterate the original string with StrAt and append the required characters to the StringBuilder. As the .NET string replace is probably optimised assembly code I would first try using that as I suspect that might be at least as fast unless the loop has to run several times for long lengths of whitespace.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote