Forms :: Find Replace Text From File - Fastest Method?
Nov 13, 20111) a text document which has content like :
uber|uber|ultra
taxi|taxi|taxi cab|cab|minicab|airport taxi|airport transfer
genitalia|genitalia|genitals
[code].....
1) a text document which has content like :
uber|uber|ultra
taxi|taxi|taxi cab|cab|minicab|airport taxi|airport transfer
genitalia|genitalia|genitals
[code].....
My current project is to process several files. The files come from a Unix server and have been SFTP'd to the Windows XP machine. (That's fixed protocol, I don't have control over it.) My problem now is that the Unix new line characters and Windows characters don't match. The solution is to read the file line by line and replace 0x0A with 0x0D + 0x0A, or Asc 10 with Asc 13 + Asc 10, or vbLf with vbCrLf, however you like to say it.Well I have a working function to do this, but any extra speed I could squeeze out of it would be fantastic. The text files I'm working with can reach sizes of about 100MB. So to the question:
Q: What is the fastest way to read a file in, change characters as necessary and then write the file out?Here is my current working code.
Private Sub FormatCharacters(ByVal files As String())
Try
For Each fileName As String In files
FileSystem.Rename(fileName, fileName & ".old")
[code]....
I am making a program for work, i have it partly coded, unfortunately i don't have a wifi connection for my laptop right now which makes it hard to add my code here. What i am trying to do is have the user pull in a text file from anywhere on the computer using a open file box that pops up, i got that part, to make sure that is working i have a textbox that reads the data of that text file, it gets pulled in fine using a stream reader. Now what i need to do is search the text file for certain values, and depending on the selected item in the listbox which is on another form, change that value in the text file, im guessing i will need to use a stream writer, and ive seen examples used based on the file location(C:....) but in my case im not sure how to do it.
View 15 RepliesI am using Visual Basic 2008 Express Edition, my goal is to read an entire .txt file that works as a template and replace all ocurances of a word with a new one and save this new modified text in a new .txt when you press a command button.
View 2 RepliesI have a project to complete and i have begun the code. What i want to do is go through the text file and find evey | (pipe) symbol and change it to a , (comma). I have the code and worked out how to do it but the code will only work for the first line. I was just wondering whether any of you had any advice on the way through this problem because i am stumped.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_ System.EventArgs) Handles Button1.Click
Dim strFile As String
[code].....
I have a small app for find and replace text in a richtextbox:
1-One button: Replace
2-Textbox1 : Find
3-Textbox2 : Replace for
But I want to know if is possible find and replace the text in the richtextbox with a xml file example:
Text in the richtextbox: "I will buy a car"
XML:
<pre lang="vb">
[Code]...
If is possible please can you give me a example code?
lswScriptreader =
New System.IO.StreamReader("test.txt", System.Text.Encoding.Default)
lswScriptwriter = File.AppendText("test1.txt")[code]....
Hex(D1) is my column Terminator and need to replace it with ",".
I have a program that will read a text file and put information from the text file into multiple text boxes. What I am trying to do now is be able to change the values in the textboxes and be able to write the specifc changes back to the text file. One way I though of doing that was using a while loop and copy the lines of the text file to another text file, then when it finds the line that has the specific change from the text box, make the change and continue writing the line until it reaches the end of the file. Then I was going to copy the file and overwrite the original, escientally making the change to the new file. Right now it will make the new file but will just make a blank text file. I think the problem is in the while loop statement but I am not sure. Here is the code below:
Code:
Private Sub submitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submitButton.Click
Dim trackname As String
[Code].....
I have to find a string in a huge text file ( ~ 50MB) and then replace it.Since it's quite huge I tend to open the file and then read line by line, and then replace the necessary line(s) (rather than "readall" the file of course).My question is how to replace the whole line?Let's say I found the line that should be replaced . I know I can create a copy file and copy all lines into there ... but I'd prefer to replace the line in the original file rather than creating a copy instance.
View 5 RepliesI would like to step through each *.txt file in a given directory, open it, find and replace all, perhaps a thousand, occurances of a given string (e.g. "00/00/00"), then close and save file, and step to next one in the directory to do the same find and replace. I've been looking at filestream classes and regular expressions but don't see a clear way to do this.
View 4 RepliesI have a bunch of object variables which are all initialised in their declarations such that:
Private _myObject As New ThisObject("SomeString")
where ThisObject is one of a number of object types, but all are initialised using a string.
I would like to use the Visual Studio Find/Replace dialog box to search for "As New" then replace everything from "As New" to the first set of speech marks with some text such that:
EDIT
My original example could be solved using other methods. This example is more representative of the actual problem:
Private _myObjectA As New ThisObjectA("SomeString")
Private _myObjectLongName As New ThisObjectLongName("SomeString")
[Code]....
I have thios code that will load a php file (text file) into a sting via streamreader then its supposed to find and replace a portion of the text and write the changes back out to the file via streamwriter. I put my code together and after running it look at the file and it's unchanged. After looking closer it appears the problem is the find & replace operation I am doing on the string. Here is my code:
[Code]...
I've been looking through the FCL for a method that will allow me to erase a line of text from a text file and replace it with another line of text. Neither the StreamReader nor StreamWriter have a method for replacing or removing Text from a text file, as does the string object. Are there any available methods for erasing just certain lines of text from a file, and then replacing them with others?
In my code, I'd like to locate a certain line in the text file, and then at that point in the text file, use a For...Next Loop to replace each successive line of the text file with new text:
Dim user_data_file As String = "user_data.txt"
edit_input = New StreamReader(user_data_file)
Dim edit_line As String = edit_input.ReadLine
[CODE]...
However, I can't find any methods that will allow me to do this.
I have a pixel I want to monitor for change. For example, first it is white, and suddenly it is black, and then changes back to white. My method is not fast enough to get this change.any changes I call the function below to get the original color of the pixel. Then I have a timer that runs every 1 ms to take the color of the pixel, and if it's not equal to original color; do something. For example counts the time the pixel has changed. However, this function does not run fast enough. Is there any faster methods to check the pixel? The function returns an ARGB code of the pixel color.[code]....
View 3 RepliesWhen ListView is not in Virtual mode the following method seems to be the fast method to load a large list into ListView:
Dim items As New List(Of ListViewItem)
Dim alllines as String()=System.IO.File.ReadAllLines("FilePath")
For each line as string in alllines
Dim item As New ListViewItem
item.Text = line
items.Add(item)
Next
ListView1.Items.AddRange(items.ToArray())
how to add a replace method to a text editor (notepad) to search for a word and replace it
1. say in (notepad) you type something in the textbox1-------"me"
2. then am suppose to type "me" in text box 2---and
3. click the find button and it suppose to find the text in textbox1
4. then you type in textbox3---- "us" and
5. click the replace button and it replaces "me" with "us"
Supose i have two TextboxOne For normal Text and Second For After Replace textif i m Type some text in textbox 1 then Textbox2 show Its Replacement Text
View 6 Replieshow to add a replace method to a text editor (notepad) to search for a word and replace it in visual basic 2005
1. say in (notepad) you type something in the textbox1-------"me"
2. then am suppose to type "me" in text box 2---and
3. click the find button and it suppose to find the text in textbox1
4. then you type in textbox3---- "us" and
5. click the replace button and it replaces "me" with "us"
Suppose:i Have Two text Box One for For Typing & second for Replacement of TextI want to Replace Text With Following:
[Code]...
I have a XML file. Inside the XML file where ever I find the string as ("C:Results est1_01") I need to replace it with ("B:final est1_01") and save it.
View 1 RepliesIn my project I have 3 different forms. They all have the same design layout so the only different you see is where the text boxes and buttons are placed. Right now I have 3 buttons at the top of each form that Im using to switch between the forms
[Code]...
I know there is probably a much better way of doing this, and faster. I dont' like the delay between each window showing/hiding. what options do I have to make this run better? Since I have the same design background is there I way I can just hide and show just the controls instead of showing/hiding the entire window?
I am attempting to make a text editor. I have a folder which contains hundreds of text files. I would like to search through all files simultaneously, for some text then replace the text with other text & save, & overwrite originals. I've got most of the basic structure done, but I've go no idea how to search for text in all files in a folder.
View 13 RepliesI have been wondering about this for a long time and have not found any ways to do this other than write my own text editor for it. Regarding the following lines of
[Code]...
I am trying to open up a text file that contains some text. I have 3 text boxes on my screen. What I need to figure out is how to replace multiple words (1 in each textbox) with text it finds in the txt file.
I can do this by using the single find / replace feature but I'm trying to be able to fill out the 3 textboxes and then click my find / replace button to have my Regex find each predefined word and replace it with what is in the text boxes.
Here is my code to get the find / replace one word at time feature. I've tinkered with this to just add more variables to my Regex but it doesn't seem to work.
[Code]...
i am trying to figure out the code for a button for application where i take test from a richtextbox read it and change the color and font i have made the application for it, with 3 buttons. find, find next and replace.
frmTextEditorMain.rtbxInput.SelectionBackColor = Color.White
frmTextEditorMain.rtbxInput.Find(tbxFind.Text)
[code].....
First it might sound like an ordinary task but keep reading it isn't. I can't figure out how to find a phrase in a text file, and replace it with something else. Tried lots of things but always ending up with empty hands.
Suppose there's a text file in this order:
valueabc=6000.0000
valuettt=200.0000
valuexyz=7000.0000
I want to;
1) Find the phrase (e.g. valueabc) by scanning the whole text,
2) Replace the number that starts after "=" and ends before ".", namely "6000" in the middle with any number value i want.
I don't need the parts before "=" and after ".", only the number in the middle.
VB.net VS 2008
I need to develop a small application which can do a batch find and replace on all xml files within a folder. Example:
<cardHolderName>
<firstName>Geraldine</firstName>
<middleName>
[Code].....
I want to replace ALL <firstName) tags to John and all <lastName> tags to Smith to protect sensitive date. In addition, there will be other tags such as address, ss number and phoneNumber.
NOTE: There may be multiple instances of <firstName> within the file. 1000 xml files with all replacing names, address etc. with the same fixed name such as John Smith These will be used for testing and to prevent sensitive data from being leaked
There is no doubt that I can do this the long and dirty way. (I am working on).
i have created a template xml file witch contain some words like {contentname}.i need to replace such a tags with my values. how to search such a words and replace using filehandling in vb.net my xml templatefile is like this:
<!-- BEGIN: main -->
<?xml version="1.0" encoding="UTF-8"?>
<OTA_HotelSearchRQ xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
[code]....
I have this code attached to a button
If htmlText.Contains("<frame src='demo.html'/>") Then
htmlText = htmlText.Text.Replace("<frame src="demo.html/>", "<frame src='" &
OpenStory.FileName)
[code].....
I've got a listbox build up as an array of items like this: First column is product id, 2nd column is name, 3rd column is price, 4th column is amount and I put them in an array: Public Item(3) As String,
7226218; Hemlock; 22.55; 0
7711175; Pine, Radiata; 12.45; 0
2229886; Pine, Arkansas; 15.25; 3[code].....
how to change the line if the Order(0) value is found in the listbox with the new amount value..