Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java the implements this function will return a copy of the original String that has all characters replaced with plus signs ("+"), with the exception of word string appearances, which are left alone.

public String plusOut(String str, String word) {
 int slen = str.length();
 int wlen = word.length();
 String fin = "";
  
 for (int i = 0; i < slen; i++) {
   if (i <= slen - wlen) {
     String tmp = str.substring(i,i+wlen);
     if (tmp.equals(word)) {
       fin += word;
       i += wlen-1;
     }
     else
       fin += "+";
   }
   else
     fin += "+";
 }
  
 return fin;
}
Source by www.coursehero.com #
 
PREVIOUS NEXT
Tagged: #Java #implements #function #return #copy #original #String #characters #replaced #signs #exception #word #string #left
ADD COMMENT
Topic
Name
3+1 =