umm... i am a new java programmer so I can't think of an easy way....
I am writing a piglatin translator(yes a common lab I am sure) but the puncuation aspect is tricky for me, here's my method thus far:
public static StringBuffer insert_punc(StringBuffer new_word, int[] punc_loc)
{String character = "";
int loc = 0;
for(int i = 1; i < punc_loc.length; i = i + 2)
{loc = punc_loc;
new_word.insert(loc, punc_loc[i+1]);
}
return new_word;
}
public static int[] find_punc(StringBuffer new_word)
{char[] punc = {'.' , ',' , ';' , '?' ,'!', ':'};
int[] punc_loc = new int[30];
int i = 0;
for(int count = 0; count < new_word.length(); count++) //cycles through the word
{for(int count2 = 0; count2 < 5; count2++) //cycle through punctuation
{if(new_word.charAt(count) == punc[count2]) //if the character is a punctuation character
{System.out.println("I: " + i);
System.out.print("Location: " + count);
punc_loc[0] = punc[count2]; //then add punctuation symbol
punc_loc[1] = count;// and it's location to array punc_loc
System.out.println(" Punc Char: " + punc[count2]);
}
}
}
System.out.println(punc_loc[0]);
System.out.println(punc_loc[1]);
return punc_loc;
}
the method names are self-explanatory( I am finding the puncuation locations, and what the character is at that point and putting it in a standary array) I just have been working on this too long and could use any help. Thx a lot :)
[1533 byte] By [
ryudena] at [2007-10-3 7:49:57]

public static StringBuffer insert_punc(StringBuffer new_word, int[] punc_loc)
{ String character = "";
int loc = 0;
for(int i = 1; i < punc_loc.length; i = i + 2)
{ loc = punc_loc;
new_word.insert(loc, punc_loc[i+1]);
}
return new_word;
}
public static int[] find_punc(StringBuffer new_word)
{ char[] punc = {'.' , ',' , ';' , '?' ,'!', ':'};
int[] punc_loc = new int[30];
int i = 0;
for(int count = 0; count < new_word.length(); count++) //cycles through the word
{ for(int count2 = 0; count2 < 5; count2++) //cycle through punctuation
{ if(new_word.charAt(count) == punc[count2]) //if the character is a punctuation character
{ System.out.println(" I: " + i);
System.out.print(" Location: " + count);
punc_loc[0] = punc[count2]; //then add punctuation symbol
punc_loc[1] = count; // and it's location to array punc_loc
System.out.println(" Punc Char: " + punc[count2]);
}
}
}
System.out.println(punc_loc[0]);
System.out.println(punc_loc[1]);
return punc_loc;
}
ok... I am making a program to translate a word into piglatin, keeping punctuation of the word in tact. StringBuffer new_word is the word that is received from the user, punc_loc is an array that I want to have store the location followed by the character at each location.
For example: if i was to enter "Bill's!"
I would want the array to look like:
[4,"'", 6, "!"]
However, in this example my code is returning the incorrect index(I think it was 33) So my question is; why is it returning an incorrect value? Where did I mess up at?
oops... This change
public static StringBuffer insert_punc(StringBuffer new_word, int[] punc_loc)
...
...
for(int i = 1; i < punc_loc.length; i = i + 2)
{ loc = punc_loc;
new_word.insert(loc, punc_loc[i+1]);
}
the 2nd line should be
loc = punc_loc[i];
PS
The insert_punc method was just put posted to show how the program works(kinda long to post whole program). Again, all i want help with is to figure out why my code isn't storing the index into the array correctly