Results 1 to 3 of 3

Thread: removing Carriage Returns

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    North east UK
    Posts
    129

    removing Carriage Returns

    Hi All,

    I have a problem, I have a text file with rows of data in the following format:

    Name:
    Bill

    Name:
    Bob

    What I would like to do is strip out the CArriage return fromthe name: line to leave

    Name:Bill

    Name:Bob

    Can I use the Trim() method to strip out carriage returns or is there another way.

    Cheers

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    I would do something like this:

    VB Code:
    1. 'Requires Imports System.IO
    2.  
    3. '/
    4.  
    5. Dim sr as New StreamReader("filePath")
    6.  
    7. Dim strFile() as String = Split(sr.ReadToEnd, vbcrlf)
    8.  
    9. sr.close
    10.  
    11. '//now assuming that your file is formmated like this
    12. '//:Name:[chr(13)]
    13. '//:Bill[chr(13)]
    14. '//:[chr(13)]
    15. '//:Name:[chr(13)]
    16. '//:Bob[chr(13)]
    17. '//:[chr(13)]
    18. '//ect....
    19.  
    20. Dim strNewFile as String
    21.  
    22. For I as Integer  = 0 to strFile.GetUpperbound(0)
    23.  
    24. Msgbox "Name: " & strFile(I)
    25.  
    26. strNewFile &= "Name: " & strFile(I) & chr(13) ' if you want to recreate the file...
    27.  
    28. Next
    29.  
    30. Dim sw as StreamWriter("filePath")
    31.  
    32. sw.Write(strNewFile)
    33.  
    34. sw.Close
    35.  
    36. '//Done
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    North east UK
    Posts
    129
    Many Thanks, that has worked a treat.

    Would it be possible to add something to this code to put in a different symbol if there was a specific word, for example:

    Name:Bill
    Name:Bob

    is now:

    Name:Bill,Name:Bob

    but if I come across:

    Name:Bill
    Name:Bob
    Number:2

    I would like it to be:

    Name:Bill,Name:Bob#Number:2
    (where i could identify the word number and prefix it with a #)

    Again, many thanks

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