|
-
Mar 1st, 2004, 09:39 AM
#1
Thread Starter
Addicted Member
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
-
Mar 1st, 2004, 12:01 PM
#2
I would do something like this:
VB Code:
'Requires Imports System.IO
'/
Dim sr as New StreamReader("filePath")
Dim strFile() as String = Split(sr.ReadToEnd, vbcrlf)
sr.close
'//now assuming that your file is formmated like this
'//:Name:[chr(13)]
'//:Bill[chr(13)]
'//:[chr(13)]
'//:Name:[chr(13)]
'//:Bob[chr(13)]
'//:[chr(13)]
'//ect....
Dim strNewFile as String
For I as Integer = 0 to strFile.GetUpperbound(0)
Msgbox "Name: " & strFile(I)
strNewFile &= "Name: " & strFile(I) & chr(13) ' if you want to recreate the file...
Next
Dim sw as StreamWriter("filePath")
sw.Write(strNewFile)
sw.Close
'//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
-
Mar 2nd, 2004, 04:40 AM
#3
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|