Hi all
I would really appreciate anyone who could help me. I am trying to convert the following string "A:B - C --> L" into a substring "(A==B) && (C==D)".
However the output I am getting from the program below is "A== &&C==". How could i change it??
class Conversion{
public static void main(String[] args){
String r = "A:B - C --> L";
// Changing the delimiter '-' to '&&'
int index = 0;
while((index = r.indexOf("-") != -1) {
char[] c1 = r.toCharArray();
char[] c2 = new char[c1.length + 1];
for(int i = 0; i < index; i++){
c2=c1;
}
c2[index+0] = '&';
c2[index+1] = '&';
r = new String(c2);
}
Changing the delimiter ':' to '=='
index = 0;
while((index = r.indexOf(":") != -1) {
char[] c1 = r.toCharArray();
char[] c2 = new char[c1.length + 1];
for(int i = 0; i < index; i++){
c2 = c1;
}
c2[index+0] = '=';
c2[index+1] = '=';
r = new String(c2);
}
System.out.println(r);
}
}
I would really appreciate anyone who could help me. I am trying to convert the following string "A:B - C --> L" into a substring "(A==B) && (C==D)".
However the output I am getting from the program below is "A== &&C==". How could i change it??
class Conversion{
public static void main(String[] args){
String r = "A:B - C --> L";
// Changing the delimiter '-' to '&&'
int index = 0;
while((index = r.indexOf("-") != -1) {
char[] c1 = r.toCharArray();
char[] c2 = new char[c1.length + 1];
for(int i = 0; i < index; i++){
c2=c1;
}
c2[index+0] = '&';
c2[index+1] = '&';
r = new String(c2);
}
Changing the delimiter ':' to '=='
index = 0;
while((index = r.indexOf(":") != -1) {
char[] c1 = r.toCharArray();
char[] c2 = new char[c1.length + 1];
for(int i = 0; i < index; i++){
c2 = c1;
}
c2[index+0] = '=';
c2[index+1] = '=';
r = new String(c2);
}
System.out.println(r);
}
}