|
List Info
Thread: Re: parsing ( strings )
|
|
| Re: parsing ( strings ) |
  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 <smanser twcny.rr.com> To: helpwithvb yahoogroups.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"
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: helpwithvb yahoogro ups.com
[mailto:helpwithvb yahoogro ups.com]
On Behalf Of Steve Trigero
Sent: Thursday, October 11, 2007 8:06 PM
To: helpwithvb yahoogro 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 ) |
  United States |
2007-10-12 11:17:53 |
|
>>>> "123__456__678__2764.987__350.456"
>>>
>> 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"
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">helpwithvb yahoogroups.com
[mailto: helpwithvb%40yahoogroups.com">helpwithvb yahoogroups.com]
On Behalf Of Steve Trigero
Sent: Friday, October 12, 2007 11:39 AM
To: helpwithvb%40yahoogroups.com">helpwithvb yahoogroups.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">smanser twcny.rr.com>
To: helpwithvb%40yahoogroups.com">helpwithvb yahoogroups.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"
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: helpwithvb yahoogro ups.com
[mailto:helpwithvb yahoogro ups.com]
On Behalf Of Steve Trigero
Sent: Thursday, October 11, 2007 8:06 PM
To: helpwithvb yahoogro 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
.
.
__._,_.___
|
[1-2]
|
|