Announcement

Collapse
No announcement yet.

removing blank spaces and entering carriage returns

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • removing blank spaces and entering carriage returns

    I have a txt file that I get from a company and it's data mashed into a txt file. I need to make this readable for our program and figure it can be done with scripting but doing scripts is NOT a strength of mine.

    What I'd like it have do is automatically run (scheduled task) at a certain time of the day and do its thing.

    The data that is sent to me looks like this:
    ABCDEF 12#500000.00XYZ ABCDE 12#500000.00XYZ ABC 12#500000.00XYZ

    What I'd like it to look like:
    ABCDEF 12#500000.00XYZ
    ABCDE 12#500000.00XYZ
    ABC 12#500000.00XYZ

    So, pretty much this is what I need:
    1) Reads the space after the last character (example here is a Z but it changes) and breaks it onto another line.
    2) Now sometimes the data comes through with two spaces between the Z and A on the wrapping of data. Need to delete that extra space.

    Any help would be appreciated.

  • #2
    Re: removing blank spaces and entering carriage returns

    please post real data and I can try to help.

    Change anything you want, but know that the code might be dependant on if the character is supposed be a number / letter / space / etc..

    Does your txt file really have XYZ or are they numbers?

    I would need to see some real data to help you out.

    Hobie

    Comment


    • #3
      Re: removing blank spaces and entering carriage returns

      Yeah, if the code was based off of exactly what you had there, it would be something like this (it kinda works ). It is using the vbscript Split Function. The last character, which is "Z", is a trigger for the split or line break. It's a starting point...

      Code:
      Const ForReading = 1
      Const ForAppending = 2
      
      strInputFile = "C:\input.txt"
      strOutputFile = "C:\output.txt"
      
      With CreateObject("Scripting.FileSystemObject")
         With .OpenTextFile(strInputFile, ForReading)
            If Err.Number <> 0 Then _
               wscript.echo "Input file not available": wscript.quit
            strContents = .ReadAll
            strContents = Split(strContents, "Z")
            .Close
         End With
         With .CreateTextFile(strOutputFile, ForAppending)
            For i = 0 to Ubound(strContents)
               strNewContents = Trim(strContents(i))  'added to remove spaces on lines
      	 'strNewContents = strContents(i)
               .WriteLine strNewContents
            Next
            .Close
         End with
      End With
      
      Msgbox "Done!"
      WScript.Quit
      Last edited by ekrengel; 29th October 2009, 21:21.

      Comment

      Working...
      X