473,568 Members | 3,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

large string manipulation

morning all,
can someone help me find the most efficient way of manipulating a large
file.

i need to replace special characters in a large file and multiple
string.replace functions are causing memory errors.

doug
Jun 7 '06 #1
3 1647
"douglas wittner" <dw******@teami nteractive.com> wrote:
can someone help me find the most efficient way of manipulating a large
file.


An efficient way for modifications that will change the length of the
file (i.e. possibly insert or delete in the middle) is to stream from
one file to another, iteratively using a buffer in memory, and working
on the buffer before streaming it out to the second file. It requires
careful buffer management to be sure that the boundaries between buffers
don't affect the outcome. For example, if searching for "foo", be
careful that one buffer doesn't end with "f" and the next one start with
"oo".

For modifications which don't change the length of the file, iteratively
reading into a smallish buffer, searching, and then using
FileStream.Seek & Write to perform updates will work reasonably well -
but not as well as a memory-mapped file, but that would be more awkward
in C#, since there is no memory-mapped file primitive.

-- Barry

--
http://barrkel.blogspot.com/
Jun 7 '06 #2
i have the reading down...while reading into a buffer, how do i perrform
the search for a character?

thanks for your help

"Barry Kelly" <ba***********@ gmail.com> wrote in message
news:tb******** *************** *********@4ax.c om...
"douglas wittner" <dw******@teami nteractive.com> wrote:
can someone help me find the most efficient way of manipulating a large
file.


An efficient way for modifications that will change the length of the
file (i.e. possibly insert or delete in the middle) is to stream from
one file to another, iteratively using a buffer in memory, and working
on the buffer before streaming it out to the second file. It requires
careful buffer management to be sure that the boundaries between buffers
don't affect the outcome. For example, if searching for "foo", be
careful that one buffer doesn't end with "f" and the next one start with
"oo".

For modifications which don't change the length of the file, iteratively
reading into a smallish buffer, searching, and then using
FileStream.Seek & Write to perform updates will work reasonably well -
but not as well as a memory-mapped file, but that would be more awkward
in C#, since there is no memory-mapped file primitive.

-- Barry

--
http://barrkel.blogspot.com/

Jun 7 '06 #3
"douglas wittner" <dw******@teami nteractive.com> wrote:
i have the reading down...while reading into a buffer, how do i perrform
the search for a character?


Either load it up into a string or character array (with an Encoding
class - and watch for split lead and trail bytes for UTF8 encoding, for
example) or scan through it with a loop, or write a more sophisticated
search such as Boyer-Moore etc.

-- Barry

--
http://barrkel.blogspot.com/
Jun 8 '06 #4

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

Similar topics

0
1420
by: Roland Hall | last post by:
I'm looking for information on working with large data files using FSO, XML. I have a program which creates a large CSV file, over 7mb. It's a rate table of freight shipping costs. There are certain fields I do not need, some are blank. A typical line would be: Raw data: " ", "30142", "GA", "01001"," ", "MA","
4
2267
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some values and separators class { private string globalvar = ""; private void manipulate (whattodo ) //substring, join, etc....
29
4293
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return substring before a pattern), AFTER (return substring after a pattern), and BETWEEN (return substring between 2 patterns). My questions are: 1. Can...
4
1345
by: moondaddy | last post by:
I have an app where users will upload photos to their shopping cart. When they review their cart I need to include a light weight thumbnail of the image they uploaded. how can I take the image a user uploaded (PixOfMom.jpg at 600k) and convert it to a thumbnail and put into the image url of a .net image control using vb.net 1.1? Thanks! ...
15
16313
by: Daren | last post by:
Hi, I need to be able to split large string variables into an array of lines, each line can be no longer than 70 chars. The string variables are text, so I would additionally like the lines to end at the end of a word, if you catch my drift. For example, I have a large string variable containing the text: "I've seen things you people...
4
3476
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if substrings need be replaced, or one character needs be changed, what shall I do? Is it better to convert strings to UCS-32 before manipulation? But...
5
7471
by: Niyazi | last post by:
Hi, Does anyone knows any good code for string manipulation similar to RegularExpresion? I might get a value as string in a different format. Example: 20/02/2006 or 20,02,2006 or 20.02.2006 etc... And I want to replace the /,.etc character with - (as 20-02-2006)
10
5875
by: Peter Duniho | last post by:
This is kind of a question about C# and kind of one about the framework. Hopefully, there's an answer in there somewhere. :) I'm curious about the status of 32-bit vs 64-bit in C# and the framework classes. The specific example I'm running into is with respect to byte arrays and the BitConverter class. In C# you can create arrays larger...
7
2094
Frinavale
by: Frinavale | last post by:
I currently have a .NET application that has an object which passes a string (a connection string) as a parameter to another object that does database manipulation. This string isn't stored anywhere else and is only used by this behind-the-scenes object to provide the database manipulation object with a connection string. Does my connection...
0
7601
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...
0
7913
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7659
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...
0
7962
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...
1
5496
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...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2099
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
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
931
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...

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.