Hi guys I am have some difficulty jumping back to a line in the code given the there goto is not supported my set up is java 7.2 I have graduated from C programming to java hence the problem !
The object is the remove the wrapping from the authors i a string containing an unknown number of authors , in this example i just repeat the same author but in real life they will be different, so what i need to do is pull out each and process it so i end up with the authors without the wrappings
[{Dr}{Seuss}][{Dr}{Seuss}][{Dr}{Seuss}] initial string
Dr Seuss, Dr Seuss, Dr Seuss required string with separating comas and non at the last author
What is have done so far is to check the length of the string so i can run a loop till all chars have been processed
Then i detected in that loop the occurrence of “ ] [ “ thus counting the number of authors
Next I find the end of the string }] and the start of the last element in the string [{ so now i am in a position to create a sub string and put the results in an array next i reduce the author count by one and if non zero i need to get back to the top to start over and if the new reduced string was the original input
[{Dr}{Seuss}][{Dr}{Seuss}] this being the sub string and then the loop needs to run again to give [{Dr}{Seuss}] and finally author count equals zero then i will drop out of the loop and process what has been put into the array to complete the desired output Dr Seuss, Dr Seuss, Dr Seuss
I call the class from main like this
public class PullOutAuthor { /** * @param args the command line arguments */ public static void main(String[] args) { unwrape unw = new unwrape("[{Dr}{Seuss}][{Dr}{Seuss}][{Dr}{Seuss}]"); } }
package pulloutauthor; /** * * @author Pete */ public class unwrape { public unwrape(String authorstring) { System.out.println(authorstring); String Newstring = ""; String Remaining = ""; String[] authorStore; authorStore = new String[10]; // place to stor 10 authors int NumberOfAuthors = 1; This is where i need to get back to so the string gets processed again in it’s new form int positionOfLastChar = 0; int positionOffirsChar = 0; int numChar = authorstring.length();// get the length of the string for (int i = 0; i < numChar - 1; i++) { // this section finds out how many authors there are char Mychar = authorstring.charAt(i); char Mychar2 = authorstring.charAt(i + 1); if (Mychar == ']' && Mychar2 == '[') { NumberOfAuthors++; } } for (int j = 0; j < numChar - 1; j++) { char Mychar = authorstring.charAt(j); char Mychar2 = authorstring.charAt(j + 1); if (Mychar == '}' && Mychar2 == ']') { positionOfLastChar = j; } if (Mychar == '[' && Mychar2 == '{') { positionOffirsChar = j; } } for (int k = positionOffirsChar + 2; k < positionOfLastChar; k++) { char Mychar3; Mychar3 = authorstring.charAt(k); Newstring = Newstring + Mychar3; } System.out.println(NumberOfAuthors); System.out.println(numChar); System.out.println(positionOffirsChar); System.out.println(positionOfLastChar); authorStore[1] = Newstring; NumberOfAuthors--; if (NumberOfAuthors != 0) { System.out.println("more to do"); Remaining = authorstring.substring(0, 26); System.out.println(authorStore[1]); System.out.println(Remaining); } } }