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 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
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
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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,...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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: 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...
|
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,...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |