keepworking
asked on
recursion
//this method will remove the text between [ and ], the input string may contains more than 1 pair of [].
it doesn't work, please let me know what is wrong in this recursion method. thanks
public static String remove_text(String text) throws IOException{
if(text.length()>0){
String text_after = null;
if(text.contains("[")&&tex t.contains ("]")){
int begin_index =text.indexOf("[");
int end_index =text.indexOf("]");
text_after = text.substring(0,begin_ind ex-1) + text.substring(end_index+1 , text.length()-1);
remove_replacement_text(te xt_after);
}
return text_after;
}
return text;
it doesn't work, please let me know what is wrong in this recursion method. thanks
public static String remove_text(String text) throws IOException{
if(text.length()>0){
String text_after = null;
if(text.contains("[")&&tex
int begin_index =text.indexOf("[");
int end_index =text.indexOf("]");
text_after = text.substring(0,begin_ind
remove_replacement_text(te
}
return text_after;
}
return text;
ASKER
objects:
thanks first.
it compiles, I did try text_after = remove_replacement_text(te xt_after); it doesn't work.
remove_text(String text) will remove the text between [ and ], for example, text is:
1 [1] [2] [3]
after, should be:
1
thanks first.
it compiles, I did try text_after = remove_replacement_text(te
remove_text(String text) will remove the text between [ and ], for example, text is:
1 [1] [2] [3]
after, should be:
1
you should call remove_text(text_after) instead of remove_replacement_text(te xt_after).
> remove_text(String text) will remove the text between [ and ], for example, text is:
your calling remove_replacement_text, *not* remove_text
your calling remove_replacement_text, *not* remove_text
ASKER
asood314:
I did call remove_text(text_after) , that is typo. :-(
I did call remove_text(text_after) , that is typo. :-(
> text_after = text.substring(0,begin_ind ex-1) + text.substring(end_index+1 , text.length()-1);
and that should be:
text_after = text.substring(0,begin_ind ex) + text.substring(end_index+1 , text.length());
and that should be:
text_after = text.substring(0,begin_ind
what output are you getting?
ASKER
my output is:
1 [2] [3
1 [2] [3
objects is right; it should be text.length() not text.length() -1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
whats this method do
remove_replacement_text(te
you need to assign the value by the looks
text_after = remove_replacement_text(te