PDA

View Full Version : سوال: replace



anisaanisa
شنبه 02 شهریور 1387, 14:09 عصر
مشکل این کد کجاست؟؟
پرینت روی صفحه درسته اما داخل فایل جابجا نمیکنه
چرا؟؟
String getname=t3.getText();
String getformul=t2.getText();
FileInputStream fis = new FileInputStream("text.txt");
int size = fis.available();
byte[] data = new byte[size];
fis.read(data, 0, size);
String fc = new String(data);
//if name found in this file
if (fc.indexOf(getname) >= 0) {
//find name position
int idx = fc.indexOf(getname);
//find comma position in the same line that find the name
int idx1 = fc.indexOf(",", idx);
String o2=fc.substring(idx1+1);
//in t2 typed edited formula(new one)
String edited=t2.getText()+"\n";
//replace old formula with new one
String res = fc.replace(o2, edited);
//System.out.println(res);
}

TheSpecialOne
شنبه 02 شهریور 1387, 17:21 عصر
String getname=t3.getText();
String getformul=t2.getText();
FileInputStream fis = new FileInputStream("text.txt");
int size = fis.available();
byte[] data = new byte[size];
fis.read(data, 0, size);
String fc = new String(data);
//if name found in this file
if (fc.indexOf(getname) >= 0) {
//find name position
int idx = fc.indexOf(getname);
//find comma position in the same line that find the name
int idx1 = fc.indexOf(",", idx);
String o2=fc.substring(idx1+1);
//in t2 typed edited formula(new one)
String edited=t2.getText()+"\n";
//replace old formula with new one
String res = fc.replace(o2, edited);
//System.out.println(res);
}