Results 1 to 6 of 6

Thread: [RESOLVED] Delimit based on Space

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Resolved [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:
    1. Private Sub Command1_Click()
    2.     Dim str As String
    3.     Dim lines() As String
    4.    
    5.     Open "C:\file.txt" For Input As #1
    6.         str = Input(LOF(1), #1)
    7.         lines = Split(str, vbNewLine)
    8.         For N = LBound(lines) To UBound(lines)
    9.             word = Split(lines, " ")
    10.         Next N
    11.     Close #1
    12.    
    13.     For N = LBound(newText) To UBound(newText)
    14.         str = str & newText(N)
    15.     Next N
    16.    
    17.     Open "C:\newFile.txt" For Output As #2
    18.         Print #2, str
    19.     Close #2
    20. End Sub

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Delimit based on Space

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim word() As String
    3.    
    4.     Open "C:\file.txt" For Input As #1
    5.         words = Split(Input(LOF(1), #1), " ")
    6.     Close #1
    7.    
    8.     For N = 0 To UBound(words)
    9.         str = str & words(N)
    10.     Next N
    11.    
    12.     Open "C:\newFile.txt" For Output As #2
    13.         Print #2, str
    14.     Close #2
    15. End Sub
    (Not sure what you want your end result to be.. this code splits by space then rebuilds the string with no spaces??)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Delimit based on Space

    this will do the same thing... removes spaces (and vbcrlf (vbNewLine))
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim str As String
    3.    
    4.     Open "C:\file.txt" For Input As #1
    5.         str = Input(LOF(1), #1)
    6.     Close #1
    7.    
    8.     str = Replace(str, " ", "")
    9.     str = Replace(str, vbCrLf, "")
    10.    
    11.     Open "C:\newFile.txt" For Output As #2
    12.         Print #2, str
    13.     Close #2
    14. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    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

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Delimit based on Space

    give this a shot then

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim word() As String
    3.    
    4.     Open "C:\file.txt" For Input As #1
    5.         words = Split(Replace(Input(LOF(1), #1), vbCrLf, ""), " ")
    6.     Close #1
    7.    
    8.     For N = 0 To UBound(words)
    9.         str = str & words(N) & vbCrLf
    10.     Next N
    11.    
    12.     Open "C:\newFile.txt" For Output As #2
    13.         Print #2, str
    14.     Close #2
    15. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Delimit based on Space

    Thank you, it works

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width