473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Regular Expression or Code

I have a problem and I am looking for suggestions. Here is the situation:

I am writing a VB.NET app to convert a string into a markup language used in
a program we have at my company. The languange handles CrLf's very stragly.
It doesn't ignore them like HTML. It will read and print them when there
are two or more in a row, but it ignores a single CRLF. To do a single line
break, you need to use the command .br; however, two CRLF's register as two
line breaks. That's right. I said two. Oh, just to make things a little
more challenging, replacing every CRLF with a .br doesn't work. The app
only reads the first .br and ignores the rest..

I can't say much for the markup languange , but it is what I have to work
with. Here is what I need to do when I parse the string:

I need to replace a single CRLF with a .br.
I need to leave two or more CRLFs in a row the way they are.

I am looking for a regular expression that would accomplish this, but code
that does the same thing would work too. In other words, any suggestions
would be appreciated.

Thanks,
Matt
Nov 21 '05 #1
5 1340
Matt,

To make it more clear to me, you need to do something as

mytext = mytext.replace(" " & VBCRLF & " ",".br")

Cor

I have a problem and I am looking for suggestions. Here is the situation:

I am writing a VB.NET app to convert a string into a markup language used in a program we have at my company. The languange handles CrLf's very stragly. It doesn't ignore them like HTML. It will read and print them when there
are two or more in a row, but it ignores a single CRLF. To do a single line break, you need to use the command .br; however, two CRLF's register as two line breaks. That's right. I said two. Oh, just to make things a little
more challenging, replacing every CRLF with a .br doesn't work. The app
only reads the first .br and ignores the rest..

I can't say much for the markup languange , but it is what I have to work
with. Here is what I need to do when I parse the string:

I need to replace a single CRLF with a .br.
I need to leave two or more CRLFs in a row the way they are.

I am looking for a regular expression that would accomplish this, but code
that does the same thing would work too. In other words, any suggestions
would be appreciated.

Thanks,
Matt

Nov 21 '05 #2
Doh, error

mytext = mytext.replace(VBCRLF & VBCRLF, "@#AnonexistingText&^")
mytext = mytext.replace(VBCRLF, ".br")
mytext = mytext.replace("@#AnonexistingText&^", VBCRLF & VBCRLF)

Keep in mind that the replace is moslty more than 100 times faster than the
regex.

I hope this helps?

Cor
Nov 21 '05 #3
Very, very nearly what I needed. Your approach helped me find the solution.
I only had to add one more replace to make sure the .br wasn't there AT ALL
if there was more then one vbCrLf:

mytext = mytext.replace(vbCrLf & vbCrLf, "@#AnonexistingText&^")
mytext = mytext.Replace(vbCrLf, vbCrLf & ".br" & vbCrLf)
mytext = mytext.Replace("@#AnonexistingText&^", vbCrLf & vbCrLf)
mytext = mytext.Replace(vbCrLf & vbCrLf & ".br", vbCrLf)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Doh, error

mytext = mytext.replace(VBCRLF & VBCRLF, "@#AnonexistingText&^")
mytext = mytext.replace(VBCRLF, ".br")
mytext = mytext.replace("@#AnonexistingText&^", VBCRLF & VBCRLF)

Keep in mind that the replace is moslty more than 100 times faster than the regex.

I hope this helps?

Cor

Nov 21 '05 #4
Oh, and by the way, thanks! =)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Doh, error

mytext = mytext.replace(VBCRLF & VBCRLF, "@#AnonexistingText&^")
mytext = mytext.replace(VBCRLF, ".br")
mytext = mytext.replace("@#AnonexistingText&^", VBCRLF & VBCRLF)

Keep in mind that the replace is moslty more than 100 times faster than the regex.

I hope this helps?

Cor

Nov 21 '05 #5
Matt,
With 4 or more replaces in a row like that I would consider using a
StringBuilder instead of re-creating the string each time.

Something like:

Dim sb As New System.Text.StringBuilder(mytext, mytext.Length * 2)

sb.Replace(vbCrLf & vbCrLf, "@#AnonexistingText&^")
sb.Replace(vbCrLf, vbCrLf & ".br" & vbCrLf)
sb.Replace("@#AnonexistingText&^", vbCrLf & vbCrLf)
sb.Replace(vbCrLf & vbCrLf & ".br", vbCrLf)

mytext = sb.ToString()

The "mytext.Length * 2" is how big a buffer the StringBuilder is going to
work with, I would attempt to calculate the largest result string
(intermediate also) that would occur from the Replacements...

With 3 or 4 replacements I would probably go with your code as is, unless
there was a performance problem, then I would try the StringBuilder to see
if that helped or hurt.

Hope this helps
Jay

"Matt" <ki*******@hotmail.com> wrote in message
news:d52Uc.29867$Jo1.16794@lakeread01...
Very, very nearly what I needed. Your approach helped me find the solution. I only had to add one more replace to make sure the .br wasn't there AT ALL if there was more then one vbCrLf:

mytext = mytext.replace(vbCrLf & vbCrLf, "@#AnonexistingText&^")
mytext = mytext.Replace(vbCrLf, vbCrLf & ".br" & vbCrLf)
mytext = mytext.Replace("@#AnonexistingText&^", vbCrLf & vbCrLf)
mytext = mytext.Replace(vbCrLf & vbCrLf & ".br", vbCrLf)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Doh, error

mytext = mytext.replace(VBCRLF & VBCRLF, "@#AnonexistingText&^")
mytext = mytext.replace(VBCRLF, ".br")
mytext = mytext.replace("@#AnonexistingText&^", VBCRLF & VBCRLF)

Keep in mind that the replace is moslty more than 100 times faster than

the
regex.

I hope this helps?

Cor


Nov 21 '05 #6

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
6
by: JohnSouth | last post by:
Hi I've been using a Regular expression to test for valid email addresses. It looks like: \w+(\w+)*@\w+(\w+)*\.\w+(\w+)* I've now had 2 occassions where it has rejected and email address...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
0
by: altavim | last post by:
Usually when you make regular expression to extract text you are starting from simple expression. When you got to know target text, you are extending your expression. Subsequently very hard to ready...
14
by: Andy B | last post by:
I need to create a regular expression that will match a 5 digit number, a space and then anything up to but not including the next closing html tag. Here is an example: <startTag>55555 any...
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.