daguilar01
I made a post earlier, but it seems to have been deleted or moved?
i pmed ComSec he said my question was within forum regulations, so not to sure why it was moved or deleted

I am looking for, a way to replace all instances of "String1" with "AlteredString1" in a text file "List.txt"
"String1" should show up in List.txt 2 times, so i am looking for outside code that can do this, i have used google over the last 2 days, and i did find one example code that did exactly this
i thought i had added it to my favorites so i could go back and look at it, but when i came back the next morning it was not in my favorites.
ive been looking and trying differnt search strings in google but i cant seem to find that code again.

Thank you in Advance
Daguilar01
Droezel
You'd have to use the streamreader and streamwriter classes. Don't have my Visual Studio installed at the moment so I can't make an example now, but you can find all the info you need here:

Streamreader:
http://msdn.microsoft.com/library/default....rclasstopic.asp

Streamwriter:
http://msdn.microsoft.com/library/default....rclasstopic.asp

Good luck!

edit: maybe if I have the time I'll have a look at it tomorrow fellow 'MW-dude' wink.gif ...
technoboy
Here are my 2 favorites options:

1. Open Notepad, use the search, replace function.

2. Learn the power of regular expression, that can be easily done in perl

CODE

#!/usr/bin/perl

while (<>) {
   s/string1/string2/g;
   print;
}


hope it help, your post was not really clear to me.
daguilar01
i'll try and explain a bit better, i am already using the SreamReader and StreamWriter to read from files and write to other files

heres a clearer representation of my situation, smile.gif
CODE
File:String1.txt      File:NewStrings.txt
----------------      -------------------
    string1               string1
    string2               string2Changed
    string3               AlteredString3
    string4               string4

File:MasterFile.txt   File:NewMasterFile.txt
-------------------   ----------------------
Name1: string1         Name1: string1
Name2: string2         Name1: string2Changed
Name3: string3         Name1: AlteredString3
Name4: string4         Name1: string4
[1=String1]            [1=string1]
other info             other info
blha info              blha info
ealdaas  info          ealdaas  info
noead dkdiv            noead dkdiv
[2=String2]            [2=String2Changed]
other info             other info
blha info              blha info
ealdaas  info          ealdaas  info
noead dkdiv            noead dkdiv
[3=String3]            [3=AlteredString3]
other info             other info
blha info              blha info
ealdaas  info          ealdaas  info
noead dkdiv            noead dkdiv
[4=String4]            [4=String4]
stupid info            stupid info
blip blap              blip blap
ding dang              ding dang
aldfvlde               aldfvlde

so as you can see, i have 2 files, one file has the before string, and the second file has the after string
i am already using the StreamReader and StreamWriter to read the first string file, then im using the Streamwriter to write out the new file with the new altered names
i want to go into the MasterFile.txt and find all instances of the first string in String1.txt and repalce it with the first string in NewStrings.txt, and find the 2nd string in String1.txt and replace it wiht the second string in NewStrings.txt
and i want to keep doing this until i run out of strings in String1.txt or NewStrings.txt, but either or, since they should contain the same number of lines(strings)
Faceless Master
hmm..Here is the solution.
Write this statement on top on your project.
Imports Microsoft.VisualBasic
Use the Stream Reader class and read the text file to a string variable.
The use the Replace Function and voila...
Example.
YourString=Replace(YourString,"text to search for","Text to replace with",1)
'Where YourString is the variable the has the contents of the text file.
~Regards
Faceless Master
FiNaLBeTa
VN.net can't replace entire strings. (ore it just didn't work for me)

CODE
 Private Sub makenormallistIPlist()
       txtInputIPlist.Text = ""
       Dim dTelip As Double
       Dim stext As String
       Dim sFile As String

       For Each sFile In ofdIPlist.FileNames
         Dim slijn As String
         FileOpen(1, sFile, OpenMode.Input)
           Do Until EOF(1)
               slijn = LineInput(1)
                if slijn = "string 1" then
               stext = stext & "altered text" & vbCrLf
               else : stext = stext & slijn & vbCrLf
               end if      
           Loop
           FileClose(1)
       Next
       txtInputIPlist.Text = txtInputIPlist.Text & stext
   End Sub


that replaces strings from a file and outputs it to a txtbox.
the code might notw work, i just ripped it out a x-scan parser i made. but it should give you a good example
FiNaLBeTa
i forgot, you need to import "Imports System.IO"
daguilar01
ok thx final beta, will try that out soon, need to work out a previous flaw first, tongue.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.

 
Invision Power Board © 2001-2005 Invision Power Services, Inc.