![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Newbie
Join Date: Mar 2006
Posts: 21
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#12 |
|
Newbie
Join Date: May 2006
Posts: 28
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#13 |
|
Newbie
Join Date: Mar 2006
Posts: 21
Rep Power: 0
![]() |
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 ![]() |
|
|
|
|
|
#14 |
|
Newbie
Join Date: Mar 2006
Posts: 21
Rep Power: 0
![]() |
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... |
|
|
|
|
|
#15 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 136
Rep Power: 0
![]() |
where is the error located?
|
|
|
|
|
|
#16 |
|
Newbie
Join Date: Mar 2006
Posts: 21
Rep Power: 0
![]() |
doesn't matter, I just found out the entire idea I was basing it on doesn't work.
I'm starting over again... |
|
|
|
|
|
#17 |
|
Newbie
Join Date: May 2006
Posts: 28
Rep Power: 0
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|