How to parse a delimited string

  • Thread starter Thread starter paul.schrum
  • Start date Start date
P

paul.schrum

I am storing listbox values in my own collection. Each item in the
collection has text delimited by semicolons as follows:


Item(1) might be "217;133"
Item (2) might be "833;199"

I am trying to write a function that will give me one integer by using
the other integer as an index. The number of entries will always be
small, so the time-overhead is not a concern.

I want to write this function:

Public Function getByColumnNumber(text as String, colNum as Integer) as
Integer

In which the input string (text) would be of the above form
("num1;num2"). It is okay if I restrict it to working only with
2-column strings.

So getByColumNumber("833;199", 2) would return the integer 199. I can
do this if I can figure out how to parse a string. In C we have
strtok. Is there an equivelent to that in VC for Access. If not, is
there a good way to write the function I want to write?

- Paul
 
I am trying to write a function that will give me one integer by using
the other integer as an index. The number of entries will always be
small, so the time-overhead is not a concern.

I want to write this function:

Public Function getByColumnNumber(text as String, colNum as Integer) as
Integer

In which the input string (text) would be of the above form
("num1;num2"). It is okay if I restrict it to working only with
2-column strings.

So getByColumNumber("833;199", 2) would return the integer 199. I can
do this if I can figure out how to parse a string. In C we have
strtok. Is there an equivelent to that in VC for Access. If not, is
there a good way to write the function I want to write?

I'm not sure it's what you mean but would this do it?:

Public Function getByColumnNumber(sText As String, colNum As Integer) As
Integer
Dim a() As String
a = Split(sText, ";")
getByColumnNumber = a(colNum - 1)
End Function



Jesper Fjølner
 
Public Function getByColNumber(ByVal strValues As String, _
ByVal intColumn As Integer) As Integer

Dim astrWork() As String

astrWork = Split(strValues, ";")
getByColNumber = CInt(astrWork(intColumn - 1))

End Function
 
I would use the Split() function and then your Index-1 as the index into the
Array.

I am storing listbox values in my own collection. Each item in the
collection has text delimited by semicolons as follows:


Item(1) might be "217;133"
Item (2) might be "833;199"

I am trying to write a function that will give me one integer by using
the other integer as an index. The number of entries will always be
small, so the time-overhead is not a concern.

I want to write this function:

Public Function getByColumnNumber(text as String, colNum as Integer) as
Integer

In which the input string (text) would be of the above form
("num1;num2"). It is okay if I restrict it to working only with
2-column strings.

So getByColumNumber("833;199", 2) would return the integer 199. I can
do this if I can figure out how to parse a string. In C we have
strtok. Is there an equivelent to that in VC for Access. If not, is
there a good way to write the function I want to write?

- Paul
_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 
Thank you to all of you who responded. The function you gave me does
exactly what I need.

- Paul
 
Back
Top