에 대한 사실 반환하지 않는 이유는 두 문자열하지 equal.Here 내 코드입니다 :같음() 나는 이유를 발견하지 못한 두 개의 동일한 문자열
public static void main(String[] args) {
JTextArea jt=new JTextArea();
jt.append("why \n me?"); //i set a test value to the JTextArea
Document doc = jt.getDocument();
Element root = doc.getDefaultRootElement();
Element element = root.getElement(0);
int start = element.getStartOffset();
int end = element.getEndOffset();
//the code above is what i specifically need for my app, to bring a
//specific line from a JTextArea
String s;
try {
s=doc.getText(start, end - start);
System.out.print("s = "+s);
if(s.equals("why")) //i expect equals() here to return true
System.out.print("s equals "+s);
else
System.out.print("s is not equal to "+s);
} catch (BadLocationException ex) {
ex.getStackTrace();
}
}
나는이 프로그램을 실행 한 후 얻을 결과 : 당신이
s=doc.getText(start, end - start);
당신은새로운 라인 앞에 공백을 가지고
s = why
s is not equal to why
''왜 ''에 해당되지 사용할 수 있습니다에' "왜"' – Eran
프로그램의 = "왜 \ n을"에서 – justMe