Computer Science Canada Java syntax is simular, please assist! |
Author: | TokenHerbz [ Sat Dec 24, 2011 9:39 pm ] | ||
Post subject: | Java syntax is simular, please assist! | ||
My problem is that I cant seem to break up my string into arrays of strings of the integers, being determined by the first number of the string. This is coded in Processing, an easier formatted type of java, So Thats why i'm posting it here...
I want to beable to break up the above string by doing the following, The first number is a 6, represents the next 6 letters as array 1... then after that is a 7, represents the next 7 letters as array 2... and so fourth.. the array should maintain the string format not adding the numbers up into a sum.... thanks for any ideas/suggestions, the error im getting now "StringOutOfBounds" however before that, with no errors, it would not show that the arrays had any values added, just a blank "". |
Author: | Tony [ Sat Dec 24, 2011 9:47 pm ] | ||
Post subject: | RE:Java syntax is simular, please assist! | ||
the heck is going on here?
Specifically, start printing out string_position at each iteration, and see if it's what you expect it to be. |
Author: | TokenHerbz [ Sat Dec 24, 2011 9:54 pm ] |
Post subject: | RE:Java syntax is simular, please assist! |
Nope its not what i expect it to be at all, sigh.. thanks i'll start with that. |
Author: | TokenHerbz [ Sat Dec 24, 2011 10:03 pm ] |
Post subject: | RE:Java syntax is simular, please assist! |
my first outputs should be 6/7/7 im constantly getting 6/2/*, i'll have to rethink this... |
Author: | TokenHerbz [ Sat Dec 24, 2011 10:16 pm ] |
Post subject: | RE:Java syntax is simular, please assist! |
tony if you could give me some logic code to help me out?! I would appreciate that, that is if you understand what im aiming for.. |
Author: | Tony [ Sat Dec 24, 2011 10:54 pm ] |
Post subject: | RE:Java syntax is simular, please assist! |
Reading things one character at a time would probably be easier to think about. At the very least, it works much better than reading them one at a time and also jumping ahead Quote: for (int string_position = 0; string_position <= encoded_message.length(); string_position++) { //-1 because array starts at 0 not 1. count_char_length = encoded_message.charAt(string_position); //finds how long the character is amount_of_characters += 1; //we have a new character we add it characters = expand(characters, amount_of_characters); //increase our array to match how much chars we have string_position += amount_of_characters; //skip the rest of the numbers, getting the length of the next char to use. } That doesn't really work. |
Author: | S_Grimm [ Sat Dec 24, 2011 11:27 pm ] | ||
Post subject: | RE:Java syntax is simular, please assist! | ||
if i understand this right, the string at array[0] should be the first 6 letters (numbers) to after the first digit. Then array[1] should be the next 7 characters after 7. Now, starting at the 7 that occurs, you are at element 7 in string[x]? would you not be able to substring that starting at element X and ending at element X+Y where Y = the number before the X? also what if the third iteration (being 7) makes attempts to access an element out the bounds of the length of the string? I realize thats not happening here, but??? ie
sorry if im not making sense, i think i have an idea of what your trying to do. ill type something else out monday or tuesday when im fully awake. |
Author: | crossley7 [ Sun Dec 25, 2011 10:43 am ] | ||
Post subject: | RE:Java syntax is simular, please assist! | ||
you could have a similar type of code, except change the for to be
This would require declaring the string position variable beforehand, but should identify the characters you want |
Author: | TokenHerbz [ Sun Dec 25, 2011 12:38 pm ] | ||
Post subject: | RE:Java syntax is simular, please assist! | ||
I have reworked this code however im getting an out of range error with my string, which i wrote this out and it should work. the place in the string + the length of the character should not exceed the length of the string even at the end.
my logic is this, 6 = amount of string in the char 421870 should be assigned to the first array 6 position = 1 + length of char = 6 totals 7, which is next char. cycle adding the values to the array is like this starting position = 2 (being the 4). counts 0 .. length (6) - 1, being 6 positions but letting me go like starting position (2) + counting max (5) = 7 .. which is last number to add the 0. 6421870 1234567 if you understand that?! Would like some insight... thanks! |
Author: | TokenHerbz [ Thu Dec 29, 2011 1:08 am ] | ||
Post subject: | RE:Java syntax is simular, please assist! | ||
Solved it, if your interested heres the code:
The decoded message is as follows: "Hey Derek, merry X-mas! I hope you are having a good break. Doing lots of Java practice I assume? What's that? You haven't?!? You've been getting drunk and hitting on hot babes?!? Good to hear! I'll see you in the new year. Cheers!" |