Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 25th, 2006, 11:48 AM   #11
chillypacman
Newbie
 
Join Date: Mar 2006
Posts: 21
Rep Power: 0 chillypacman is on a distinguished road
I now have the 'english to 1337' part done very well, and it works 100%, thank you all for your help

I'm going to start the reverse of it, however it seems to be somewhat problematic.

Since 1337 letters can consist of more than just one character I can't simply use a loop and go through each character individually and replace them as needed, I need to scan the strings. Since there will be a space between each 1337 character I can easily tell the computer when one letter stops and another starts, however I have no idea how I can tell the computer to replace one 1337 string with an english character.

So would anyone have any ideas how best it would be to approach this problem?
chillypacman is offline   Reply With Quote
Old May 25th, 2006, 11:53 AM   #12
NSchnarr
Newbie
 
Join Date: May 2006
Posts: 28
Rep Power: 0 NSchnarr is on a distinguished road
I would use a switch statement. read the first letter into a string using the substring method. Compare that in a switch statement to all the pre-defined "1337" characters, it it equals add that corresponding letter to a String. If it does not equal, use two letters (subString(n, n+2)), repeat until there is a match.
I dont see any point to using arrays for this.
NSchnarr is offline   Reply With Quote
Old May 25th, 2006, 11:59 AM   #13
chillypacman
Newbie
 
Join Date: Mar 2006
Posts: 21
Rep Power: 0 chillypacman is on a distinguished road
well I am using the arrays to store the letters inside them...

I'm a little tired right now, (2am), but I'll look into switch statements next time I start working on it again.

Thanks
chillypacman is offline   Reply With Quote
Old May 26th, 2006, 3:26 AM   #14
chillypacman
Newbie
 
Join Date: Mar 2006
Posts: 21
Rep Power: 0 chillypacman is on a distinguished road
I'm on the verge of making it work, however I keep getting an index out of bounds exception, here is the code thus far:
import java.util.*;

public class cba
        
{
    public static void main(String [] args) {
        
        //For all incrementing purpouses, the int variables i and x are
        //used, and set to the required value
        int i = 0;
        int x = 0;
        //Creates an array of 26 index locations to store the 1337 alphabet
        //within.
        String[] leet = new String[27];
        
        //a
        leet[0] = "/-\\";
        //b
        leet[1] = "|3";
        //c
        leet[2] = "[";
        //d
        leet[3] = "|)";
        //e
        leet[4] = "3";
        //f
        leet[5] = "|=";
        //g
        leet[6] = "9";
        //h
        leet[7] = "|-|";
        //i
        leet[8] = "1";
        //j
        leet[9] = ";";
        //k
        leet[10] = "|<";
        //l
        leet[11] = "|_";
        //m
        leet[12] = "|\\/|";
        //n
        leet[13] = "|\\|";
        //o
        leet[14] = "0";
        //p
        leet[15] = "|*";
        //q
        leet[16] = "*|//";
        //r
        leet[17] = "|2";
        //s
        leet[18] = "5";
        //t
        leet[19] = "7";
        //u
        leet[20] = "|_|";
        //v
        leet[21] = "\\/";
        //w
        leet[22] = "\\/\\/";
        //x
        leet[23] = ")(";
        //y
        leet[24] = "'/";
        //z
        leet[25] = "2";
        //<space>
        leet[26] = " ";
        
        
        /* creates an array and stores all the letters of the ASCII value of
        each letter in the alphabet within it in each index, it does this by
        inititializing variable x with 65, the ASCII value of A in the alphabet
         */
        x = 65;
        int[] abc = new int[27];
        while( i < 26) {
            abc[i] = x;
            x++;
            i++;
        }
        //26th index position for space's in the abc[] array.
        abc[26] = 32;
        
		Scanner keyboard = new Scanner(System.in);
        
        System.out.println("Input the 1337 sentence to translate to english: ");
        String sentence = keyboard.nextLine();
        
        
        
        
        
        int sentenceLength = sentence.length();
        
        //creates a char array of the sentence.
        char letters[] = sentence.toCharArray();
        
        //creates another char array to store newly interpreted letters within
        String[] translated = new String[10 * sentence.length()];
        
        i = 0;      
        x = 0;
        int y = 0;
        int numStrings = 0;
        
        
        
        //This loop will find out how many strings there are within the 
        //setence and store it within numStrings.
        while ( y < sentenceLength )
        {
        	
        	if( sentence.charAt(x) == abc[26] )
        	{
        		numStrings++;
        	}
        	x++;
        	y++;
        }
        
        System.out.println(numStrings);
        
        
        x = 0;
        y = 0;
        i = 0;
        
        //this is the new array nextWord[], its length is determined by the
        //number of strings there were in the charArray sentence.
        String[] nextWord = new String[numStrings];
        
        //this loop uses the variable numStrings as its termination value, the
        //purpouse of this loop is to add a new string in each index of the
        //array nextWord[].
        while ( y < numStrings )
        {
        	
        	if( sentence.charAt(x) == abc[26] )
        	{
        		nextWord[i] = sentence.substring(i);        		
        		i++;
        	}
        	
        	sentenceLength--;
        	x++;
        	y++;
        }  
             	       
        i = 0; 
        //prints the words (testing purpouses)...
        /*while ( i < numStrings )
        {
        	if ( nextWord[i] == null )
        	{
        		break;
        	}	 
        	System.out.print( nextWord[i] );
        	i++;
        } */
          
        i = 0;
        x = 0;
        
        
        //begins interpretation loop
        while ( i < numStrings )
        {
        	
        	if ( nextWord[i] == leet[x] )
        	{
        		System.out.print( abc[x] );
        		i++;
        		x = -1;		
        	}
        	
        	
        	x++;
        }
        
        System.out.println();        
   }
}

I don't understand why its makking the index out of bounds error though...
chillypacman is offline   Reply With Quote
Old May 26th, 2006, 8:14 AM   #15
Toro
Hobbyist Programmer
 
Toro's Avatar
 
Join Date: Apr 2006
Posts: 136
Rep Power: 0 Toro is an unknown quantity at this point
where is the error located?
Toro is offline   Reply With Quote
Old May 26th, 2006, 9:42 AM   #16
chillypacman
Newbie
 
Join Date: Mar 2006
Posts: 21
Rep Power: 0 chillypacman is on a distinguished road
doesn't matter, I just found out the entire idea I was basing it on doesn't work.

I'm starting over again...
chillypacman is offline   Reply With Quote
Old May 26th, 2006, 10:05 AM   #17
NSchnarr
Newbie
 
Join Date: May 2006
Posts: 28
Rep Power: 0 NSchnarr is on a distinguished road
using a switch, or nested if statement even should allow this to be done within a while loop. there is no need for arrays, just temporary string variables.
NSchnarr is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:02 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC