473,486 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Conditional Search and Replace?

I'm receiving bytes over a socket and displaying in a text box. In the
responses I receive, some lines are delimited with x0A and others with
x0D0A. I'd like to search for x0A and replace with x0D0A, but only if x0A is
preceeded with x0D - so I don't end up with x0D0D0A.

Right now I'm searching for x0D0A, replacing with x0A, then searching for
x0A and replacing with x0D0A. Seems a little ugly.

Is there a better way to do this? I thought maybe regular expressions, but
don't know much about regex.

TIA,
Mike
Nov 20 '05 #1
2 1690
Mike,

Perhaps you can do some bit fiddling here.

As you read your stream look for the bit pattern (token) x0Dx0A using the
XOR statement

If xor yields zero then the bit patterns are identical.
Make your replacement in the output stream
move forward in your input stream the lenght of the token
Else
move forward one bit in your input stream
End If

Dan
"Mike Hildner" <mh******@afweb.com> wrote in message
news:uP*************@TK2MSFTNGP09.phx.gbl...
I'm receiving bytes over a socket and displaying in a text box. In the
responses I receive, some lines are delimited with x0A and others with
x0D0A. I'd like to search for x0A and replace with x0D0A, but only if x0A is preceeded with x0D - so I don't end up with x0D0D0A.

Right now I'm searching for x0D0A, replacing with x0A, then searching for
x0A and replacing with x0D0A. Seems a little ugly.

Is there a better way to do this? I thought maybe regular expressions, but
don't know much about regex.

TIA,
Mike

Nov 20 '05 #2
Mike,
Is there a better way to do this? I thought maybe regular expressions, but
don't know much about regex. This sounds like a good use of a RegEx

The following site seems to be a good intro to Regular-Expressions:

http://www.regular-expressions.info/

I'm sure there are others.

Unfortunately I do not use RegEx enough to give you a good working sample.

I believe you will need to use RegexOptions.Singleline to allow treating \r
& \n as characters.

Note: in RegEx: \r = x0D while \n = x0A.

Hope this helps
Jay
"Mike Hildner" <mh******@afweb.com> wrote in message
news:uP*************@TK2MSFTNGP09.phx.gbl... I'm receiving bytes over a socket and displaying in a text box. In the
responses I receive, some lines are delimited with x0A and others with
x0D0A. I'd like to search for x0A and replace with x0D0A, but only if x0A is preceeded with x0D - so I don't end up with x0D0D0A.

Right now I'm searching for x0D0A, replacing with x0A, then searching for
x0A and replacing with x0D0A. Seems a little ugly.

Is there a better way to do this? I thought maybe regular expressions, but
don't know much about regex.

TIA,
Mike

Nov 20 '05 #3

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

Similar topics

28
3411
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found...
22
11078
by: Phlip | last post by:
C++ers: Here's an open ended STL question. What's the smarmiest most templated way to use <string>, <algorithms> etc. to turn this: " able search baker search charlie " into this: " able...
3
10948
by: David Link | last post by:
Hi All, Here's a Conditional drop_table func for those interested. There was a thread on this a long time back. We do this all the time : DELETE TABLE sales; CREATE TABLE sales (...);
5
2611
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
32
14760
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...
8
5074
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
6
5848
by: Martin Evans | last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get a regular expression to do the following example in Python: Search and replace all instances of "sleeping" with "dead"....
15
1773
by: Nicholas M. Makin | last post by:
I was just thinking that I understood the conditional operator when I coded the following expecting it to fail: int a= 10, b= 20, c= 0; ((a < b) ? a : b) = c; // a=0 a=20; b= 10; ((a < b) ? a...
1
7509
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
0
7099
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
6964
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
7123
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
7175
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
6842
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
7319
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...
0
5430
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
3069
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
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.