473,695 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to efficiently find a string in multiple text files?

The text files are not only the .txt files, but also all ascii files.

Thx.
Jan 3 '06 #1
5 3432
Buddhist,

For me a txt file is the same as an ascii file. (a classic name for a text
file)

Therefore can you make it more clear for us what you mean by this.

Be aware that finding strings in compressed or hassled files is not as easy
to do as in a txt file.

Cor
Jan 3 '06 #2
O, what I described was a little confusing and didn't make sense.

Actually, I want to ask how to searh a string in lots of text files quickly.
I implemented this by using System.IO(direc tory and file), read each line
and checked whether there was string desired, then recorded line numbers.
But its performance is very low, especially while processing lots of files.
So I am doubting whether directly using System.IO can meet my performance
requirement. Do I need to do many optimization by myself? And how?

Thx.
"Cor Ligthert [MVP]" <no************ @planet.nl> 写入消息
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. .
Buddhist,

For me a txt file is the same as an ascii file. (a classic name for a text
file)

Therefore can you make it more clear for us what you mean by this.

Be aware that finding strings in compressed or hassled files is not as
easy to do as in a txt file.

Cor

Jan 3 '06 #3
Buddhist,
O, what I described was a little confusing and didn't make sense.

Actually, I want to ask how to searh a string in lots of text files
quickly.
I implemented this by using System.IO(direc tory and file), read each line
and checked whether there was string desired, then recorded line numbers.
But its performance is very low, especially while processing lots of
files.
So I am doubting whether directly using System.IO can meet my performance
requirement. Do I need to do many optimization by myself? And how?

That is in fact the only method I know as well, you can probably slightly
improve it by doing some multithreading with ony two threads, not more
(where the advantage is so low that I would not do it). (Finding the string
in an array can than be done seperated from retrieving the array).
Mutltithreading to read more files is without any sense and slows only your
application.

Have as well a look to this message from Jon some days ago.

http://groups.google.com/group/micro...149199c66b64bI hope this helps,Cor

Jan 3 '06 #4
Thx your help.

But I am dubious about the example by Jon.
Is checking each char in a huge char array very fast?
I'm afraid not.

Or there is sth I haven't understood.

"Cor Ligthert [MVP]" <no************ @planet.nl> 写入消息
news:u6******** ******@TK2MSFTN GP12.phx.gbl...
Buddhist,
O, what I described was a little confusing and didn't make sense.

Actually, I want to ask how to searh a string in lots of text files
quickly.
I implemented this by using System.IO(direc tory and file), read each line
and checked whether there was string desired, then recorded line numbers.
But its performance is very low, especially while processing lots of
files.
So I am doubting whether directly using System.IO can meet my performance
requirement. Do I need to do many optimization by myself? And how?

That is in fact the only method I know as well, you can probably slightly
improve it by doing some multithreading with ony two threads, not more
(where the advantage is so low that I would not do it). (Finding the
string in an array can than be done seperated from retrieving the array).
Mutltithreading to read more files is without any sense and slows only
your application.

Have as well a look to this message from Jon some days ago.

http://groups.google.com/group/micro...149199c66b64bI
hope this helps,Cor

Jan 4 '06 #5
Buddhist,

Sorry for Strings is the Visual Basic Find the fastest.

http://groups.google.com/group/micro...5c33cc87237dbf

See this test we did already a long while ago.

What we have tested is the Visual Basic find for finding strings twice as
fast as any other method.

Cor
Jan 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
33863
by: hokiegal99 | last post by:
How do I say: x = string.find(files, 'this', 'that', 'the-other') currently I have to write it like this to make it work: x = string.find(files, 'this') y = string.find(files, 'that') z = string.find(files, 'the-other')
14
1526
by: Klaus Neuner | last post by:
Hello, I need to gather information that is contained in various files. Like so: file1: ===================== foo : 1 2 bar : 2 4
1
3724
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: # -*- coding: utf-8 -*- # Python ﹊mport os,sys ﹎ydir= '/Users/t/web'
5
2103
by: Jim | last post by:
Hello, I am working on a small windows application for a client, and as one of the functions they want a search that will let them enter a search string, then search a directory for all flies that contain that search string AND display the lines that contain the search string. They have windows ME, XP and 2000 systems. Does anyone have any ideas as to the most efficient way to do this?
0
3077
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not want to replace all of them. You need to look at it in a case-by-case basis. What can you do? Answer: emacs.
2
3316
by: rengask | last post by:
I got the code to find and replace within an open text file. ------------------ Private Sub cmdFile_Click() Dim strTemp As String txtFile = "" dlg.FileName = "*.*" dlg.ShowOpen If Dir(dlg.FileName) <> "" Then
7
3062
by: random guy | last post by:
Hi, I'm writing a program which creates an index of text files. For each file it processes, the program records the start and end positions (as returned by tellg()) of sections of interest, and then some time later uses these positions to read the interesting sections from the file.
9
2679
by: | last post by:
I am interested in scanning web pages for content of interest, and then auto-classifying that content. I have tables of metadata that I can use for the classification, e.g. : "John P. Jones" "Jane T. Smith" "Fred Barzowsky" "Department of Oncology" "Office of Student Affairs" "Lewis Hall" etc. etc. etc. I am wondering what the efficient way to do this in code might be. The dumb and brute-force way would be to loop through the content...
9
1760
by: Jasper | last post by:
Hi, I have multiple data files which need parsing in realtime so high performance is *crucial*. I dont have a format definition, but from what I can see there is a hierarchy of data. Each data field is named thus <"name":(the <are mine). The data can be quoted text or unquoted text or a composite hierarcy field. Each name/data pair is terminated by a comma unless it is the last in the
0
8635
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we抣l explore What is ONU, What Is Router, ONU & Router抯 main usage, and What is the difference between ONU and Router. Let抯 take a closer look ! Part I. Meaning of...
0
8574
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8994
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8830
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6493
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3008
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1977
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.