Click here to Skip to main content
14,869,890 members
Articles / Programming Languages / C# 4.0
Posted 7 Jun 2011

Tagged as


1 bookmarked

L33t Tr4nsl4t0r (Leet Translator)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (8 votes)
13 Jun 2011CPOL
This is an alternative to "L33t Tr4nsl4t0r (Leet Translator)".

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;


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.



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


About the Author

Luc Pattyn
Software Developer (Senior)
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. Pin
Kim Togo8-Jun-11 1:29
professionalKim Togo8-Jun-11 1:29 
GeneralReason for my vote of 5 Fine version with simple code. Pin
thatraja13-Jun-11 19:53
professionalthatraja13-Jun-11 19:53 
GeneralRe: Thanks Raja. Pin
Kim Togo14-Sep-11 6:26
professionalKim Togo14-Sep-11 6:26 
GeneralHi Luc. I have an updated version with the improvements you ... Pin
Kim Togo8-Jun-11 0:59
professionalKim Togo8-Jun-11 0:59 
GeneralRe: I don't know what the expected action would be. Personally, ... Pin
Luc Pattyn8-Jun-11 1:27
sitebuilderLuc Pattyn8-Jun-11 1:27 
GeneralReason for my vote of 5 Super approach Luc! I will try to co... Pin
Kim Togo7-Jun-11 20:44
professionalKim Togo7-Jun-11 20:44 

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

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