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