Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Go to top

L33t Tr4nsl4t0r (Leet Translator)

, 13 Jun 2011
Rate this:
Please Sign up or sign in to vote.
Way too much code. Using arrays of characters, your switch constructs can be reduced to just a few lines of code, like so:switch (c) { case 'a': sb.Append("4"); break; case 'e': sb.Append("3"); break; case 'i': sb.Append("1"); break; ...
Way too much code. Using arrays of characters, your switch constructs can be reduced to just a few lines of code, like so:
switch (c)
         {
           case 'a': sb.Append("4"); break;
           case 'e': sb.Append("3"); break;
           case 'i': sb.Append("1"); break;
           case 'o': sb.Append("0"); break;
           case 'A': sb.Append("4"); break;
           case 'E': sb.Append("3"); break;
           case 'I': sb.Append("1"); break;
           case 'O': sb.Append("0"); break;
           default: sb.Append(c); break;
         }
becomes:
string rep="43104310";
int index= "aeioAEIO".IndexOf(c);
if (index<0) sb.Append(c);
else sb.Append(rep[index]);
where rep is used to further improve readability.
Smile | :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Luc Pattyn
Software Developer (Senior) Perceler
Belgium Belgium
I am an engineer with a background in electronics, software and mathematics.
 
I develop technical software, both for embedded systems and for desktop equipment. This includes operating systems, communication software, local networks, image processing, machine control, automation, etc.
 
I have been using all kinds of microcontrollers and microprocessors (Intel 4004/8080/8051/80386/Pentium, Motorola 680x/680x0/ColdFire/PowerPC, Microchip PIC, Altera NIOS, and many more), lots of programming languages (all relevant assemblers, Fortran, Basic, C, Java, C#, and many more), and different operating systems (both proprietary and commercial).
 
For desktop applications and general development tools I have been using both UNIX systems and Mac/MacOS for many years, but I have switched to x86-based PCs with Windows, Visual Studio and the .NET Framework several years ago.
 
I specialize in:
- cross-platform development (making software that runs on diverse hardware/OS combinations)
- instruction set simulation
- improving software performance, i.e. making sure the software runs the job at hand in as short a time as possible on the given hardware. This entails algorithm selection, implementation design, accurate measurements, code optimisation, and sometimes implementing virtual machines, applying SIMD technology (such as MMX/SSE), and more.

Comments and Discussions

 
GeneralRe: Thanks Luc :-) I will add an alternate. PinmemberKim Togo8-Jun-11 1:29 
GeneralReason for my vote of 5 Fine version with simple code. Pinmvpthatraja13-Jun-11 19:53 
GeneralRe: Thanks Raja. PinmemberKim Togo14-Sep-11 6:26 
GeneralHi Luc. I have an updated version with the improvements you ... PinmemberKim Togo8-Jun-11 0:59 
GeneralRe: I don't know what the expected action would be. Personally, ... PinmvpLuc Pattyn8-Jun-11 1:27 
GeneralReason for my vote of 5 Super approach Luc! I will try to co... PinmemberKim Togo7-Jun-11 20:44 
Reason for my vote of 5
Super approach Luc!
I will try to come up with an modified version and taking your idea with it.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 13 Jun 2011
Article Copyright 2011 by Luc Pattyn
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid