VB.NET Replace Statement
VB.NET Replace Statement
VB.NET Replace Statement
VB.NET Replace Statement
VB.NET Replace Statement
VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement
VB.NET Replace Statement VB.NET Replace Statement
VB.NET Replace Statement
Go Back  Xtreme Visual Basic Talk > > > VB.NET Replace Statement


Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2004, 01:56 PM
gpwake gpwake is offline
Newcomer
 
Join Date: Nov 2003
Posts: 14
Default VB.NET Replace Statement


I am reading a text file in Line by Line, then trying to replace specific characters. Below is a sample line of the text as it appears in the text file:

869|1460|0|12/31/2003|1:30, 5:20, 9:00 pm.|Y|N|N|13|N|

My code is as follows:

FileOpen(1, "C:\inetpub\wwwroot\feed\sc16.txt", OpenMode.Input)
Do Until EOF(1)
Input(1, LineOfTextSC)

' Format line of text
LineOfTextSC = Replace(LineOfTextSC, ",", "-")


As you can see i want to replace , with - which for some reason just wont work. When VB reads the above line in it places a return where there is a comma followed by a space. In short it breaks my one line into three:

869|1460|0|12/31/2003|1:30
5:20
9:00 pm.|Y|N|N|13|N|

My end result needs to be:
869|1460|0|12/31/2003|1:30-5:20-9:00 pm.|Y|N|N|13|N|

Any help would be great.
Reply With Quote
  #2  
Old 01-06-2004, 02:15 PM
reboot's Avatar
rebootVB.NET Replace Statement reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

Look at String.Replace and StringBuilder.Replace
Reply With Quote
  #3  
Old 01-07-2004, 02:22 AM
AndreRyan AndreRyan is offline
Contributor
 
Join Date: Jan 2002
Posts: 489
Default

And look into Streams(System.IO) they are much faster than the File* commands which are compatibility and shouldn't be used anyway.
__________________
If you're a beginner or have little experience don't launch into something beyond your abilities, for example don't start game programming by trying to make a 3D first person shooter if you have no idea how to use DirectX and/or OpenGL or how to keep track of objects in a 2D plane let alone a 3D one.
Reply With Quote
  #4  
Old 01-09-2004, 05:44 PM
gpwake gpwake is offline
Newcomer
 
Join Date: Nov 2003
Posts: 14
Default

Quote:
Originally Posted by AndreRyan
And look into Streams(System.IO) they are much faster than the File* commands which are compatibility and shouldn't be used anyway.



Can you give me a basic sample?

Everytime my program runs across a comma it acts as if it is followed by a new line of text. I have tried to replace vbCrLF but that doesn't seem to work either.

Dim LineOfTextSC As String
FileOpen(1, "C:\inetpub\wwwroot\feed\sc.txt", OpenMode.Input)

Do Until EOF(1)
Input(1, LineOfTextSC)
AllText = AllText & LineOfTextSC & Wrap
Loop

TextBox1.Text = AllText
FileClose(1)

Thanks,
gpwake
Reply With Quote
  #5  
Old 01-09-2004, 11:25 PM
reboot's Avatar
rebootVB.NET Replace Statement reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

You need to dump all that old VB6 stuff. Here's an example of reading a text file a line at a time with a stream reader.

Code:
Dim sr As StreamReader Dim sin As String 'open the textfile sr = File.OpenText("C:\inetpub\wwwroot\feed\sc.txt") 'read the first line sin = sr.ReadLine() 'loop through the file While Not sin Is Nothing 'do something with the input string 'read another line sin = sr.ReadLine() End While 'close the reader sr.Close()
Reply With Quote
  #6  
Old 01-09-2004, 11:29 PM
reboot's Avatar
rebootVB.NET Replace Statement reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default

And if you want to read the entire file all at once

Code:
Dim sr As StreamReader Dim alltext As String 'open the textfile sr = File.OpenText("C:\inetpub\wwwroot\feed\sc.txt") 'read the whole file alltext = sr.ReadToEnd() 'close the reader sr.Close()
Reply With Quote
  #7  
Old 01-12-2004, 10:02 AM
gpwake gpwake is offline
Newcomer
 
Join Date: Nov 2003
Posts: 14
Default

Quote:
Originally Posted by reboot
And if you want to read the entire file all at once

Code:
Dim sr As StreamReader Dim alltext As String 'open the textfile sr = File.OpenText("C:\inetpub\wwwroot\feed\sc.txt") 'read the whole file alltext = sr.ReadToEnd() 'close the reader sr.Close()



Thanks! I will give this a shot.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.Net Office Integration FAQ Mike Rosenblum .NET Office Automation 2 12-19-2003 01:17 PM
MySQL: How to know the Insert statement is finish Angelus Database and Reporting 0 05-29-2003 03:09 AM
Code Checkers? meteo General 9 04-08-2003 11:57 PM
What's the future hold for VB? Ashington Sid Tech Discussions 18 06-04-2002 01:20 PM
A VB6 to VB.NET conversion sample Helmar General 0 11-14-2001 06:27 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
VB.NET Replace Statement
VB.NET Replace Statement
VB.NET Replace Statement VB.NET Replace Statement
VB.NET Replace Statement
VB.NET Replace Statement
VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement VB.NET Replace Statement
VB.NET Replace Statement
VB.NET Replace Statement
 
VB.NET Replace Statement
VB.NET Replace Statement
 
-->