Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Basic4ppc Wishlist
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Basic4ppc Wishlist Missing any feature?

Split string with multiple separators

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2009, 12:16 PM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default Split string with multiple separators

I have a requirement which might not be specific to me... I put the suggestion here even though it might best be met by an extension of StringsEx.dll.

The strings I want to split have been crudely formatted with tabs and spaces to render into columns when using a fixed-width font. Fortunately all columns have a visible character, so when correctly split no element would be null.

Unfortunately the StrSplit(string, "") function will, quite reasonably, treat each white-space character as delineating a new column.

Could we have a version that ignores multiple whitespace? Or a function that does not do a split but contracts all whitespace into, say, a single space? I think it would need a StringBuilder object to do this reasonably efficiently in Basic4PPC code.

Mike.
Reply With Quote
  #2 (permalink)  
Old 12-02-2009, 02:23 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
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
  #3 (permalink)  
Old 12-03-2009, 09:59 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 762
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hi Andrew, thanks for those suggestions.

The replacing of space-pairs with singles is something I have done with such files in a basic editor like Notepad in times gone by, but when treating larger runs of spaces I used a "binary chop" sort of sequence, halving the number of spaces (from, say, 64) to replace each time and thus reducing the number of repetitions. Since StringBuilder offers an easy way to halve the length of the replacement set of spaces each time I might try an automation of that...

Mike.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
1 sub for multiple events Simontelescopium Questions (Windows Mobile) 3 12-04-2009 02:03 PM
RegEx-library - Split ? moster67 Basic4ppc Wishlist 11 09-15-2008 05:51 PM
Multiple Listviews tsteward Questions (Windows Mobile) 2 04-20-2008 11:16 AM
How to play multiple sounds at once? justdo Questions (Windows Mobile) 2 09-24-2007 04:59 AM
Supporting multiple resolutions davidmw Basic4ppc Wishlist 2 07-24-2007 12:34 PM


All times are GMT. The time now is 04:11 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0