Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old April 2nd, 2008, 08:42 AM
swalker1595 swalker1595 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 3 swalker1595 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 5 sec
Reputation Power: 0
Change/remove text from file

I want to remove the specified text from a text file or i can change the text to ""

Reply With Quote
  #2  
Old April 2nd, 2008, 10:10 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,025 sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 4 h 38 m 59 sec
Reputation Power: 608
Quote:
Originally Posted by swalker1595
I want to remove the specified text from a text file or i can change the text to ""

Can you give a little bit more information and post any code that you have already? Do you know how to open the text file?

Not tested, but try something like this to loop through the contents of a text file, remove any occurances of a certain string, and re-write the file:
Code:
Dim aLine, searchCriteria, outputString As String
searchCriteria = "Whatever you want to search for"
outputString = ""
open "C:\test.txt" for input As #1
While NOT EOF(1)
	Line Input #1, aLine
	If InStr(aLine, searchCriteria) Then
		aLine = Replace(aLine, searchCriteria, "")
	End If	
	outputString = outputString & aLine & vbCrLf
Wend
Close #1
Open "C:\test.txt" for output As #1
Print #1, outputString
Close #1

If this isn't what you are looking for you will have to post a detailed description of your problem.

Reply With Quote
  #3  
Old April 4th, 2008, 08:07 AM
swalker1595 swalker1595 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 3 swalker1595 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 5 sec
Reputation Power: 0
Quote:
Originally Posted by sync_or_swim
Can you give a little bit more information and post any code that you have already? Do you know how to open the text file?

Not tested, but try something like this to loop through the contents of a text file, remove any occurances of a certain string, and re-write the file:
Code:
Dim aLine, searchCriteria, outputString As String
searchCriteria = "Whatever you want to search for"
outputString = ""
open "C:\test.txt" for input As #1
While NOT EOF(1)
	Line Input #1, aLine
	If InStr(aLine, searchCriteria) Then
		aLine = Replace(aLine, searchCriteria, "")
	End If	
	outputString = outputString & aLine & vbCrLf
Wend
Close #1
Open "C:\test.txt" for output As #1
Print #1, outputString
Close #1

If this isn't what you are looking for you will have to post a detailed description of your problem.


I know how to write text to a file i know how to over write text in a file and how to open a file but i cant remove text that is surrounded by other text with out affecting the other text.

Reply With Quote
  #4  
Old April 4th, 2008, 08:29 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,025 sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 4 h 38 m 59 sec
Reputation Power: 608
Quote:
Originally Posted by swalker1595
I know how to write text to a file i know how to over write text in a file and how to open a file but i cant remove text that is surrounded by other text with out affecting the other text.

I dont think there is any way you can achieve what you want in a standard text file, unless it is set up for Random access.

What format is your text file in? And is there any reason why you cant do as per my example and just recreate the text file without the bit of text that you want to remove?

Reply With Quote
  #5  
Old April 8th, 2008, 02:45 AM
garman garman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 32 garman User rank is Corporal (100 - 500 Reputation Level)garman User rank is Corporal (100 - 500 Reputation Level)garman User rank is Corporal (100 - 500 Reputation Level)garman User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 13 m 45 sec
Reputation Power: 2
could do a specific text search, then space() the number of chrs to replace the text with white space?

Reply With Quote
  #6  
Old April 14th, 2008, 03:19 PM
rpeare rpeare is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 467 rpeare User rank is First Lieutenant (10000 - 20000 Reputation Level)rpeare User rank is First Lieutenant (10000 - 20000 Reputation Level)rpeare User rank is First Lieutenant (10000 - 20000 Reputation Level)rpeare User rank is First Lieutenant (10000 - 20000 Reputation Level)rpeare User rank is First Lieutenant (10000 - 20000 Reputation Level)rpeare User rank is First Lieutenant (10000 - 20000 Reputation Level)rpeare User rank is First Lieutenant (10000 - 20000 Reputation Level)rpeare User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 4 Days 7 m 47 sec
Reputation Power: 117
Do you have any other info you can share?

For instance let's say the string in your file is:

Code:
XXX THIS IS MY TEST STRING XXX


and you want to remove the string "TEST" from the file you want it to appear when you're done as:

Code:
XXX THIS IS MY STRING XXX


or

Code:
XXX THIS IS MY      STRING XXX


Code:
Sub main()

Dim fs
Dim f1
Dim f2
Dim sSourceFile as string
Dim sTargetFile as string
Dim sSearchString as string
Dim sline As String

sSourceFile = "c:\TestText.txt"
sTargetFile = "c:\TestTextTemp.txt"
sSearchString = "TEST"

Set fs = CreateObject("Scripting.filesystemobject")
Set f1 = fs.opentextfile(sSourceFile)
Set f2 = fs.createtextfile(sTargetFile)

Do While f1.atendofstream <> True
    sline = f1.readline
    'Use this line to replace with a string of equal length spaces
    'sline = Replace(sline, sSearchString, 
String(Len(sSearchString), " "))
    'Use this line to replace the string with a blank
    'sline = Replace(sline, sSearchString, "")
    f2.writeline sline
    
Loop

f1.Close
f2.Close

fs.deletefile sSourceFile
fs.movefile sTargetFile, sSourceFile

End Sub


This will replace every instance of your search string with your replacement string on any given line. When the code is done running it will delete your original file and rename the temporary file to the original file name.
__________________
----------------
If we've helped you and you have solved your problem please post that it's been resolved so we know! The suspense kills me!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Change/remove text from file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway