473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

String Manipulation Alternatives to RegEx

Tom
I have string that is 2.5 million bytes long.

I tried using Regular Expressions to look for patterns and replace the
pattern found with a pre-defined text. This works great on some computers
but on some others (win 2K server 1gig of ram) it times out!

So I am looking for an alternative method as I've been told Regular
Expressions are expensive.

Here is my pattern;
white spaces followed by a new line (\n) followed by more spaces plus
a predefined string.

For each occurance, I want to replace this pattern with a predefined string,
thereby removing all the blank lines, cr lf.
Does anyone know of an alternative method to try?
Can you provide an example?
Thanks

Tom

Nov 16 '05 #1
4 4241
Tom,

The regular expression doesn't time out, rather, the request is timing
out. You have to change the executionTimeout value in the httpRuntime
element in the web.config file to extend the timeout of the request.

Also, I would seriously consider using something else if you have 2.5
million bytes of text to search through, as using a regular expression is
not the most efficient manner (you have to load the text to be searched on
as a string, and allocating THAT much continuous memory is going to kill
you).

I would look for third party components that can work on a file, or work
on a stream.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tom" <To*@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
I have string that is 2.5 million bytes long.

I tried using Regular Expressions to look for patterns and replace the
pattern found with a pre-defined text. This works great on some computers
but on some others (win 2K server 1gig of ram) it times out!

So I am looking for an alternative method as I've been told Regular
Expressions are expensive.

Here is my pattern;
white spaces followed by a new line (\n) followed by more spaces plus
a predefined string.

For each occurance, I want to replace this pattern with a predefined
string,
thereby removing all the blank lines, cr lf.
Does anyone know of an alternative method to try?
Can you provide an example?
Thanks

Tom

Nov 16 '05 #2
Tom
Can you recommend any third party tools?

Also, what's weired is I have several RegEx on this string. All of the
other RegEx's work very fast! So I don't know if the file size is the issue.
Maybe, its my RegEx?

Thanks

Tom
"Nicholas Paldino [.NET/C# MVP]" wrote:
Tom,

The regular expression doesn't time out, rather, the request is timing
out. You have to change the executionTimeout value in the httpRuntime
element in the web.config file to extend the timeout of the request.

Also, I would seriously consider using something else if you have 2.5
million bytes of text to search through, as using a regular expression is
not the most efficient manner (you have to load the text to be searched on
as a string, and allocating THAT much continuous memory is going to kill
you).

I would look for third party components that can work on a file, or work
on a stream.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tom" <To*@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...
I have string that is 2.5 million bytes long.

I tried using Regular Expressions to look for patterns and replace the
pattern found with a pre-defined text. This works great on some computers
but on some others (win 2K server 1gig of ram) it times out!

So I am looking for an alternative method as I've been told Regular
Expressions are expensive.

Here is my pattern;
white spaces followed by a new line (\n) followed by more spaces plus
a predefined string.

For each occurance, I want to replace this pattern with a predefined
string,
thereby removing all the blank lines, cr lf.
Does anyone know of an alternative method to try?
Can you provide an example?
Thanks

Tom


Nov 16 '05 #3
"Tom" <To*@discussions.microsoft.com> wrote in
news:A1**********************************@microsof t.com...
I have string that is 2.5 million bytes long.

I tried using Regular Expressions to look for patterns and replace the
pattern found with a pre-defined text. This works great on some computers
but on some others (win 2K server 1gig of ram) it times out!
Regular expressions don't have timeouts.
So I am looking for an alternative method as I've been told Regular
Expressions are expensive.

Here is my pattern;
white spaces followed by a new line (\n) followed by more spaces plus
a predefined string.
Maybe you should post that pattern.
It somehow sounds as if you had a pattern like "\s*\n\s*PredefinedString".
Is that the case? Also post your Regex settings.
For each occurance, I want to replace this pattern with a predefined
string,
thereby removing all the blank lines, cr lf.
Does anyone know of an alternative method to try?


- "for" loop
- "while" loop
- "foreach" loop

Niki
Nov 16 '05 #4
Tom,
Does anyone know of an alternative method to try?
Rather then read the entire string into memory, have you considered
processing one or two lines at a time using a StreamReader & a state
machine?

Basically read the first line, if its blank, remember it, and read the next
line, if its the pattern, drop the first line, change the next line, write
the next line, read a new first line.

If the first line is not blank, write it

If the next line is not the pattern, write the first line, making the next
line the new first line.

If ???

I would probably work out what the state machine for the above before
attempting to code...

Hope this helps
Jay


"Tom" <To*@discussions.microsoft.com> wrote in message
news:A1**********************************@microsof t.com...I have string that is 2.5 million bytes long.

I tried using Regular Expressions to look for patterns and replace the
pattern found with a pre-defined text. This works great on some computers
but on some others (win 2K server 1gig of ram) it times out!

So I am looking for an alternative method as I've been told Regular
Expressions are expensive.

Here is my pattern;
white spaces followed by a new line (\n) followed by more spaces plus
a predefined string.

For each occurance, I want to replace this pattern with a predefined
string,
thereby removing all the blank lines, cr lf.
Does anyone know of an alternative method to try?
Can you provide an example?
Thanks

Tom

Nov 16 '05 #5

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

Similar topics

10
by: Kevin | last post by:
Is there a way to search a string for the number of times a certain character shows up without having to write my own function? string var = "111-222-33.33-2" var.countchar(var) = 3
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
2
by: Aaron | last post by:
I would like to randomly output phone numbers seperated by \ and / from a string. s = "\231-3423/\453-1234/\231-3473/\231-3474/" //c sharp code private string GetPhoneNum() { s =...
11
by: Jon | last post by:
I want to count the number of instances of a certain string(delimiter) in another string. I didn't see a function to do this in the framework (if there is, please point me to it). If not, could...
7
by: Brian Mitchell | last post by:
Is there an easy way to pull a date/time stamp from a string? The DateTime stamp is located in different parts of each string and the DateTime stamp could be in different formats (mm/dd/yy or...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
3
by: ommail | last post by:
Hi I wonder if regular expressions are in general sower than using classes like String and Char when used for validating/parsing text data? I've done some simple test (using IsMatch()) method...
15
by: nagar | last post by:
I need to split a string whenever a separator string is present (lets sey #Key(val) where val is a variable) and rejoin it in the proper order after doing some processing. Is there a way to use...
1
by: kru | last post by:
Hi All, Simple issue I cannot figure out. I have a multiline textbox, I need to convert the string contents of this textbox into a single line string which I currently write to a textfile. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.