- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
/*
*
*
*/
public class Chapter1 {
private String text[] = { "Returns a new string that is a ",
"substring of this string" };
private String splitted[];
private int k = 2; //
private char c = '<';
public void run() {
for (int i = 0; i < text.length; i++) {
text[i] = makeString(text[i], change(i));
System.out.println(text[i]);
}
}
/*
*
*/
private String makeString(String textLine, String[] changed) {
StringBuilder sBui = new StringBuilder(textLine);
int i = 0; // changed index
int beginIndex = 0;
for (int j = 0; j < splitted.length; j++) {
beginIndex = sBui.indexOf(splitted[j], beginIndex); // word begin
int endIndex = beginIndex + splitted[j].length(); // word end
if(splitted[j].length() > k){
sBui.delete(beginIndex, endIndex);
sBui.insert(beginIndex, changed[i++]);
}
beginIndex = endIndex;
}
return sBui.toString();
}
/*
*
*
*/
public String[] change(int i) {
splitted = text[i].split("\t|\n| ");
for (int indx = 0; indx < splitted.length; indx++) {
if (splitted[indx].length() > k) {
StringBuilder sBuild = new StringBuilder(splitted[indx]);
sBuild.setCharAt(k, c);
splitted[indx] = sBuild.toString(); // irasomas pakeistas zodis
}
}
return splitted;
}
} // end