From: olczyk@... (Thaddeus L. Olczyk) Date: 2001-12-17T02:15:34+09:00 Subject: [ruby-talk:28695] How do you do "character filtering" of a string using each_byte. II There has been a trend I noticed in the last few years of the Usenet. Basically it has been the dumbing down of Usenet. It used to be that when you posted to a car (specific brand) group, a question like "Why won't my car start?" with a detailed lists of specs and symptoms, and you would get an answer from someone which would be useful to a person with a modicum of mechanical aptitude. ( Assuming that the problem is not to sever. ) Now the same question will get you an answer like "Is there gas in your car?" despite the fact that you said that you just filled the tank and the gauge reads full. And the people that could help you assume that your question is another posted by someone who forgets to gas up his car. In the last few weeks I've seen some pretty dumb things such as: 1) In a Borland group I asked if the behavior of winsock was any different under Borland than Microsoft compilers. To which I got answers suggesting socket component libraries ( which I told them I was not interested in ). It wasn't till I made a nasty comment that I got answer ( from a guy who is actually pretty cool ), he then suggested I use ACE. The irony is that I am listed as a contributor to ACE ( actually to TAO, really only about five lines ). 2) In one of the linux groups someone asked about an OmniView, the KVM that I use. Someone responded that many computers need a constant signal telling them that the mouse is connected and that they would need an electronic switch ( duh the OmniView is the best electronic switch available ). What they failed to tell the guy is that Logitech mice fail with the wheel mouse drivers on linux when using an OmniView. The only solution would be to use the plain drivers. I could go on but I need to go. If I wanted to I could probably go on for pages with similar examples. After a while it just gets tiring. I had hoped that ruby was different. There just seemed to be a more "serious programmer" language. Also the presence of the pragmatic progammers would seem to dictate a better tone. Also since rub is derivative of ST and many of the ST posters seem to be cool. Worse is that the answeres I've seen are very similar to the VB/VisualC++ with wizards mentality of avoiding understanding how the language handles certain things. ( In this case how ruby handles things. ) Prefering instead a set of hacks which together solve the problem. Never mind that when the boss comes in and specifies some modifications three new hacks go on top of the old hacks. Then next time three more hacks go on top... etc. Until the code becomes unmanagable. Hopefully it is an abberation to this group. In any case I now present a version of the problem where the basics almost have to be handled. Given a string I want a function to produce a string that replaces the characters by the following rule. 1) If the character is lower-case, I want it replaced by \x followed by the hex value. 2) If the character is upper-case, I want it replaced by \ followed by the octal represntation. 3) If the character is a digit I want it replaced by \b followed by the binary representation. 4) If the character is otherwise printable I want it replaced by \d followed by the base ten representation. 5) If the character is notpritable I want it replaced by \4 and the base four representation. For the truely intelligent who try this, thanks.