Thanks for antiplastik's method, it works. but there are still some syntax error exist.
Code:void setup() {
size(200,200);
String stringA = " aaaa aaa aaa";
String stringB = "xxxx xxxx xxxxxxxxxxx xxx";
replace(stringA,stringB);
}
void replace(String stringA,String stringB) {
if ((stringA != null) || (stringB != null)) {
String outString;
char[] charA = stringA.toCharArray();
char[] charB = stringB.toCharArray();
int maxium = max (charA.length,charB.length);
charA = expand(charA,maxium);
charB = expand(charB,maxium);
for (int i=0; i < maxium ; i++) {
if (charB[i] !=' ') {
charA[i] = charB[i];
}
}
outString = new String(charA);
println(charA);
println(outString);
// return outString;
}
}
this can be complied, and works well.
but what expecting is return the String back from this function.
Code: void setup() {
size(200,200);
String stringA = " aaaa aaa aaa";
String stringB = "xxxx xxxx xxxxxxxxxxx xxx";
String x = replace(stringA,stringB);
Println (x);
}
String replace(String stringA,String stringB) {
if ((stringA != null) || (stringB != null)) {
String outString;
char[] charA = stringA.toCharArray();
char[] charB = stringB.toCharArray();
int maxium = max (charA.length,charB.length);
charA = expand(charA,maxium);
charB = expand(charB,maxium);
for (int i=0; i < maxium ; i++) {
if (charB[i] !=' ') {
charA[i] = charB[i];
}
}
outString = new String(charA);
//println(charA);
// println(outString);
return outString;
}
}
I get a " This method must return a result of type String"
This coding is a part of practice of string operation.
what I want is using these codes animating some ascii images. the characters on the static background can be replaced by the dynamic ones if overlapping happen.