FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How do I do this search and replace?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: How do I do this search and replace? [message #172335 is a reply to message #172332] Sun, 13 February 2011 13:33 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
Doug Miller wrote:
> In article <vscel6le4f6810hekfooookik3ircj3ue3(at)4ax(dot)com>, evan(at)theobvious(dot)espphotography(dot)com(dot)invalid wrote:
>> On Sat, 12 Feb 2011 20:23:54 -0500, Jerry Stuckle
>> <jstucklex(at)attglobal(dot)net> wrote:
>>
>>> Sorry, Evan, you've just proven you are ignorant and a troll. You
>>> aren't even intelligent enough to understand when he's right.
>> What part of "Well, it didn't work for me, so if it works for someone
>> else, more power to them." did you not understand?
>
> If it didn't work for you, clearly you implemented it wrong. Or, as seems more
> likely, you didn't actually try it at all.
>
> Here's a formal proof that Richard's method is correct:
>
> Let A be the string <a>\r\n<b>, and B the string <c>\n<d>,where <a>, <b>, <c>,
> and <d> are any arbitrary strings not containing "\n". The first operation,
> replace all "\r\n" with "\n", changes A to <a>\n<b> and leaves B untouched.
> The second operation, replace all "\n" with "\r\n", changes A to <a>\r\n<b>,
> and B to <c>\r\n<d>, which is the specified result: change \n to \r\n except
> when \n is immediately preceded with \r.
>
> If you would dispute that proof, demonstrate the flaw in it, or post a
> counterexample. Otherwise, you owe Richard an apology.
>
> Time to man up, Evan.
>
Indeed. simple problems like this, it's easy to construct state machines
for, and examine every possible combination, and produce totally
reliable bug free code. Sadly such examples are few and far between.


As someone else pointed out tho, what about a single '\r'?

Whether you implement the sate machine in a regexp, simple replacement
with string functions, or write a straight copying loop that examines
characters and pairs of characters and makes instant decisions on the
basis of comparison, is down to taste.

In terms of CPU time, its a one pass loop if you do teh latter, and ver
efficient.

Regexps are the least efficient and the most impenetrable, but they make
people feel smart, so they have their place. They hark back to the days
of teletypes and paper tapes, when code terseness was overwhelmingly
important, and all coding was done and checked on a bit of paper with a
pencil, before being laboriously entered onto The Computer. There being
only one, and far too few teletypes or time allowed on it for more than
one crack.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Curious problem
Next Topic: Hot Sameera Hot Cleavage show - Download
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 11:05:32 GMT 2024

Total time taken to generate the page: 0.03894 seconds