List Info

Thread: Re: parsing ( strings )




Re: parsing ( strings )
country flaguser name
United States
2007-10-12 10:39:19

Last_index = 5

Thanks. That was just the stuff I was looking for.


The other Steve

----- Original Message ----
From: Steve Manser <smansertwcny.rr.com>
To: helpwithvbyahoogroups.com
Sent: Friday, October 12, 2007 6:43:51 AM
Subject: RE: [helpwithvb] parsing ( strings )


>&gt; Given a string with this data:
>>;
>>; "123 456 678 2764.987 350.456"

Good Morning Steve,

In addition to what Bob has mentioned, we have,
VB-6's Split() function, and the default character
that is assumed to separate the values is a Space Character.

We can specify the delimiter ( separator thingie )
in the place for the function's second argument.

Many sep chars are used, and they all have their
own dangers and gotchas, but we often see commas,
colons, semicolons, #s, etc.

I recently found it necessary
to use a sub-string: '#_#'
rather than a single character.

Code Stuff:
------------ -

Option Explicit

Private Const NUM_00 As Long = 0&
Private Const ONE_SPACE As String = " "
Private Const TWO_SPACE As String = " "
Private Const NO_SPACES As String = ""

----

Dim Tmp As String
Dim MyArray() As String
Dim Test_Stuff As String
Dim Last_Index As Long

Tmp = NO_SPACES

Test_Stuff = "123 456 678 2764.987 350.456"

MyArray = Split(Test_Stuff, ONE_SPACE)

123 is in MyArray( 0 )
456 is in MyArray( 1 )
....and
350.456 is in MyArray( 4 )

Last_Index = UBound(MyArray, 1)

Quiz: What is the value held in 'Last_Index' ?

Hint: There were extra space chars in your string.

-----------

What to look out for, or
what will catch you out, or
what will make you throw things:

Forgetting to make sure that all of the
doubled-up, tripled-up, space characters
have been replaced with a single space character.

Yahoo may remove my extra spaces,
so we'll the use underscore character,
but only for demonstration purposes:

Test_Stuff = "__45_66___31_ _43__11_2_ __8__"

Test_Stuff = Trim$( Test_Stuff )

Tmp = Test_Stuff

Do While InStr(1, Tmp, TWO_SPACE) <> NUM_00

Tmp = Replace( Tmp, TWO_SPACE, ONE_SPACE )
Loop

Test_Stuff = Tmp

Normally I include that code, above, in a function
named something like 'Do_NutriSystems( )'

Test_Stuff = Do_NutriSystems( Test_Stuff)

Our variable now holds: "45 66 31 43 11 2 8"

Of course I should be using the names of the
retired athletes on that commercial we all
see on ESPN, but my coffee intake is low....

All The Best,
Steve
.
Sent out around
09:45 AM EST Friday, October 12, 2007
.
.
____________ _________ _________ _________ _
From: helpwithvbyahoogro ups.com
[mailto:helpwithvbyahoogro ups.com]
On Behalf Of Steve Trigero
Sent: Thursday, October 11, 2007 8:06 PM
To: helpwithvbyahoogro ups.com
Subject: [helpwithvb] parsing

Given a string with this data: ;  "123  456  678  2764.987 350.456"

Is there a parsing procedure provided in VB6 that can easily grab
one of the values? I can loop through the string myself and locate
each number, I was just wondering if VB6 provided anything for
that.

Thanks,
Steve
.
.


__._,_.___
.

__,_._,___
RE: parsing ( strings )
country flaguser name
United States
2007-10-12 11:17:53


>&gt;>> "123__456__678__2764.987__350.456&quot;
>&gt;>
&gt;> Last_index = 5

Oooops....

There seem to be just five (5) elements
in the test string, and since the Split()
returns a zero based array, IIRC....

Last_Index should hold 4
If we have removed the extra spaces.
....unless Split returns a one-based array.

Please check me on that point.

I think the extra spaces will cause our
Split() to give us extra array elements
that may be filled with zero length strings.

Last_Index could then hold, say..., 9

I could easily be wrong since I've not tested
my code and it is sourced directly out of the ether.

-----

Another thought....

If we need to find a certain value, which may or may not
be in our new array of strings that look like numbers,
we could do this...

Look_4 = "42&quot;

For X = Start_Num To Last_Index

This_Num = MyArray(X)

If StrComp(Look_4, This_Num) = Num_Zero Then

We_Found_It = True

The_Index = X

REM: Short-Circuit
X = Last_Index + 99&
End If
Next

All The Best,
Steve
.
Sent out around
12:16 Noonish EST Friday, October 12, 2007
.
.
________________________________________
From: helpwithvb%40yahoogroups.com">helpwithvbyahoogroups.com
[mailto: helpwithvb%40yahoogroups.com">helpwithvbyahoogroups.com]
On Behalf Of Steve Trigero
Sent: Friday, October 12, 2007 11:39 AM
To: helpwithvb%40yahoogroups.com">helpwithvbyahoogroups.com
Subject: Re: [helpwithvb] parsing ( strings )

Last_index = 5

Thanks. That was just the stuff I was looking for.

The other Steve
----- Original Message ----
From: Steve Manser < smanser%40twcny.rr.com">smansertwcny.rr.com>
To: helpwithvb%40yahoogroups.com">helpwithvbyahoogroups.com
Sent: Friday, October 12, 2007 6:43:51 AM
Subject: RE: [helpwithvb] parsing ( strings )

>;> Given a string with this data:
>>;
>>; "123 456 678 2764.987 350.456&quot;

Good Morning Steve,

In addition to what Bob has mentioned, we have,
VB-6's Split() function, and the default character
that is assumed to separate the values is a Space Character.

We can specify the delimiter ( separator thingie )
in the place for the function's second argument.

Many sep chars are used, and they all have their
own dangers and gotchas, but we often see commas,
colons, semicolons, #s, etc.

I recently found it necessary
to use a sub-string: '#_#'
rather than a single character.

Code Stuff:
------------ -

Option Explicit

Private Const NUM_00 As Long = 0&
Private Const ONE_SPACE As String = " "
Private Const TWO_SPACE As String = " "
Private Const NO_SPACES As String = "&quot;

----

Dim Tmp As String
Dim MyArray() As String
Dim Test_Stuff As String
Dim Last_Index As Long

Tmp = NO_SPACES

Test_Stuff = "123 456 678 2764.987 350.456&quot;

MyArray = Split(Test_Stuff, ONE_SPACE)

123 is in MyArray( 0 )
456 is in MyArray( 1 )
....and
350.456 is in MyArray( 4 )

Last_Index = UBound(MyArray, 1)

Quiz: What is the value held in 'Last_Index' ?

Hint: There were extra space chars in your string.

-----------

What to look out for, or
what will catch you out, or
what will make you throw things:

Forgetting to make sure that all of the
doubled-up, tripled-up, space characters
have been replaced with a single space character.

Yahoo may remove my extra spaces,
so we'll the use underscore character,
but only for demonstration purposes:

Test_Stuff = "__45_66___31_ _43__11_2_ __8__";

Test_Stuff = Trim$( Test_Stuff )

Tmp = Test_Stuff

Do While InStr(1, Tmp, TWO_SPACE) <> NUM_00

Tmp = Replace( Tmp, TWO_SPACE, ONE_SPACE )
Loop

Test_Stuff = Tmp

Normally I include that code, above, in a function
named something like 'Do_NutriSystems( )'

Test_Stuff = Do_NutriSystems( Test_Stuff)

Our variable now holds: "45 66 31 43 11 2 8"

Of course I should be using the names of the
retired athletes on that commercial we all
see on ESPN, but my coffee intake is low....

All The Best,
Steve
.
Sent out around
09:45 AM EST Friday, October 12, 2007
.
.
____________ _________ _________ _________ _
From: helpwithvbyahoogro ups.com
[mailto:helpwithvbyahoogro ups.com]
On Behalf Of Steve Trigero
Sent: Thursday, October 11, 2007 8:06 PM
To: helpwithvbyahoogro ups.com
Subject: [helpwithvb] parsing

Given a string with this data:   "123  456  678  2764.987 350.456&quot;

Is there a parsing procedure provided in VB6 that can easily grab
one of the values? I can loop through the string myself and locate
each number, I was just wondering if VB6 provided anything for
that.

Thanks,
Steve
.
.

__._,_.___
Recent Activity
Visit Your Group
Search Ads

Get new customers.

List your web site

in Yahoo! Search.

Best of Y! Groups

Check it out

and nominate your

group to be featured.

Find Enlightenment

Yoga groups and

resources on

Yahoo! Groups.

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )