473,795 Members | 2,452 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 1656
"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
1427
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
2275
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
4325
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 any tell me how I can implement such functionality in C#? 2. Is it possible to add/include function...
4
1359
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! -- moondaddy@nospam.com
15
16356
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 wouldn't believe. Attack ships on fire
4
3493
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 on Windows, wchar_t is 16 bits which isn't enough for characters which can't be simply encoded...
5
7495
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
5893
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 than 2^32, using the overloaded methods that take 64-bit parameters. But as near as I can tell,...
7
2108
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 string pose a security problem when it is inside the code like this? Or are connection strings...
0
9672
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’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10214
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
10164
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,...
1
7538
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
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.