From: Webbiz on
On Tue, 9 Mar 2010 18:56:44 +1100, "Michael Cole"
<invalid(a)microsoft.com> wrote:

>Webbiz wrote:
>> I've done parsing where you have one delimiter such as a comma or
>> space.
>
>[SNIP]
>
>> My thinking is this:
>>
>> 1. To first run the usual parse routine where the delimiter is the
>> SPACE character. This will break it up into "3/8-", "3/10+" and
>> "3/15".
>
>Yep - Easiest way is to use the Split comand.
>
>> 2. Run each through another filter that looks for either the - or +
>> and simply removes it.
>
>Use the Replace command twice - note that it would make more sense to do
>this first on the entire string before performing the Split.

Oh. Good idea. Strip out the "+" and "-" if exists first, then parse.

Thanks!

Webbiz

From: Webbiz on
On Tue, 9 Mar 2010 07:55:49 -0600, "Larry Serflaten"
<serflaten(a)usinternet.com> wrote:

>
>"Webbiz" <nospam(a)noway.com> wrote
>
>> My thinking is this:
>>
>> 1. To first run the usual parse routine where the delimiter is the
>> SPACE character. This will break it up into "3/8-", "3/10+" and
>> "3/15".
>>
>> 2. Run each through another filter that looks for either the - or +
>> and simply removes it.
>>
>> Is this how you would do it?
>
>I would do the reverse, first filter out anything that is not a number or the /
>and replace them with spaces. Then reduce any multi-space sections to
>just one space. Then when you use Split, they each fall into their own
>array element.
>
>Reasoning: If you use Split first, you end up with one or more items
>you have to filter. Say, on average, you end up with three items. That
>means (on average) you run Split once and Filter three times.
>
>If you filter the string first then no matter how many items there are,
>each string gets one pass through the filter and one pass through Split.
>
>LFS
>


Yes. Michael mentioned this as well to filter first. I don't know why
I didn't think of that. Oh wait, yes I do! Because I'm a bloody
greener. :-b

Thanks.

BTW, what is the function for stripping out unwanted characters and
replacing them with something else, or changing multi-space to single
space? Is there such a function or is this to be user-defined?

Thanks.

Webbiz
From: Webbiz on
On Tue, 09 Mar 2010 13:26:41 -0500, GS <GS(a)discussions.microsoft.com>
wrote:

>Here's a reusable function I adapted from a Balena sample that I use
>for the exact purpose you cite here.

>
>'Use example code snippet
>Const sCharsToKeep As String = " +"
>sText = FilterString2(sStr(4), sCharsToKeep) 'returns "3/8 3/10 3/15"
>'Process as required...
>
>HTH
>Kind regards,
>Garry
>


Worked nicely! Of course I realized that in your example " +" is a
typo. It's " /" to work correctly.

Thanks again.

Webbiz
From: GS on
I'm surprised that you got the post! It doesn't show up anywhere in my
reader OR the online UI.

I did post the corrected code immediately after seeing my typo. Glad
you caught it anyway.
--

Garry


From: Larry Serflaten on

"Webbiz" <nospam(a)noway.com> wrote

> BTW, what is the function for stripping out unwanted characters and
> replacing them with something else, or changing multi-space to single
> space? Is there such a function or is this to be user-defined?

One way to strip out unwanted characters is to use a look-up table!

The table represents all the ASCII characters. The ones you want to
keep are included in the table (at their appropreate offset) and the rest
get some other value, like 0, or in this case, a space character.

Something like this:

LFS

Private Sub Form_Load()
Debug.Print FilterDates("3/8- 3/10+ 3/15")
End Sub

Private Function FilterDates(Text As String) As String
' Allow only digits 0 to 9 plus / with dates separated by a space
Static LUT As String
Dim i As Long, ch As Long

' Build Look Up Table
If Len(LUT) = 0 Then
LUT = Space(127)
For i = 47 To 57 ' included characters
Mid(LUT, i, 1) = Chr$(i)
Next
End If

' Transfer filtered input to result
FilterDates = Space(Len(Text))
For i = 1 To Len(Text)
ch = Asc(Mid$(Text, i, 1))
Mid(FilterDates, i, 1) = Mid$(LUT, ch, 1)
Next

' Reduce spaces
While InStr(FilterDates, " ")
FilterDates = Replace(FilterDates, " ", " ")
Wend

End Function


First  |  Prev  | 
Pages: 1 2
Prev: Virtual memory increasing.
Next: Print Server