[RESOLVED] Delimit based on Space
Can anyone help me delimit text files by " "? I have searched the forums but have nto yet found anyone delimiting to pull out each word. I want to pull out each separate word of a text file. Any help would be greatly appreciated. Thank you.
VB Code:
Private Sub Command1_Click()
Dim str As String
Dim lines() As String
Open "C:\file.txt" For Input As #1
str = Input(LOF(1), #1)
lines = Split(str, vbNewLine)
For N = LBound(lines) To UBound(lines)
word = Split(lines, " ")
Next N
Close #1
For N = LBound(newText) To UBound(newText)
str = str & newText(N)
Next N
Open "C:\newFile.txt" For Output As #2
Print #2, str
Close #2
End Sub
Re: Delimit based on Space
VB Code:
Private Sub Command1_Click()
Dim word() As String
Open "C:\file.txt" For Input As #1
words = Split(Input(LOF(1), #1), " ")
Close #1
For N = 0 To UBound(words)
str = str & words(N)
Next N
Open "C:\newFile.txt" For Output As #2
Print #2, str
Close #2
End Sub
(Not sure what you want your end result to be.. this code splits by space then rebuilds the string with no spaces??)
Re: Delimit based on Space
this will do the same thing... removes spaces (and vbcrlf (vbNewLine))
VB Code:
Private Sub Command1_Click()
Dim str As String
Open "C:\file.txt" For Input As #1
str = Input(LOF(1), #1)
Close #1
str = Replace(str, " ", "")
str = Replace(str, vbCrLf, "")
Open "C:\newFile.txt" For Output As #2
Print #2, str
Close #2
End Sub
Re: Delimit based on Space
No I don't want to remove the space just want to pull out each word. For example, in the preceeding sentence I don not want: "NoIdon'twanttoremovethespacejustwanttopullouteachword"
However, I do want:
No
I
don't
want
to
remove
the
space
just
want
to
pull
out
each
word
Thanks though for the code
Re: Delimit based on Space
give this a shot then
VB Code:
Private Sub Command1_Click()
Dim word() As String
Open "C:\file.txt" For Input As #1
words = Split(Replace(Input(LOF(1), #1), vbCrLf, ""), " ")
Close #1
For N = 0 To UBound(words)
str = str & words(N) & vbCrLf
Next N
Open "C:\newFile.txt" For Output As #2
Print #2, str
Close #2
End Sub
Re: Delimit based on Space