Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Learning C from VB.NET - Assistance?

Status
Not open for further replies.

Kate32

MIS
Jan 30, 2005
6
US
I have the following code that is rather simple: it gets a user's input string and takes out the spaces and pops out each word in VB.NET. I am trying to learn C and scipting and would want to convert this to C. I would greatly appreciate any assistence!
Code:
Private Sub Tokenize_Click()
 Dim tok As New Tokenizer
 Dim s As String

 tok.init txString.Text  'set the string from the input
 lsTokens.Clear          'clear the list box
 s = tok.nextToken       'get a token
 While Len(s) > 0        'as long as not of zero length
   lsTokens.AddItem s    'add into the list
   s = tok.nextToken     'and look for next token
 Wend
End Sub
Code:
'String tokenizer class
Private s As String, i As Integer
Private sep As String   'token separator
Private stokens() As String 'array of tokens
Public Sub init(ByVal st As String)
 s = st
 setSeparator " "
End Sub
Private Sub Class_Initialize()
 sep = " "   'default is a space separator
End Sub
Public Sub setSeparator(ByVal sp As String)
  sep = sp
  stokens = Split(s, sp)
  i = -1
End Sub
Public Function nextToken() As String
 Dim tok As String
 If i < UBound(stokens) Then
   i = i + 1
   tok = stokens(i)
 Else
   tok = ""
 End If
 nextToken = tok    'return token
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top