특정 문자열의 서식을 지정하려고합니다. 나는 언젠가 저에게 노트북의 불행한 사건이 발생하여 많은 가치있는 코드를 삭제했습니다. 나는 대부분의 파일을 저장했지만 저장되지 않은 몇 가지는 안드로이드 앱에 매우 중요했습니다. 그럼 여기에 문자열을 포맷하려고하는 코드가 있습니다. 각 줄의 시작 부분에있는 모든 숫자가 없어야합니다. 약 3600 명이 있습니다. Android Studio에서 JAVA로 문자열 서식 지정
//inside onCreate method
String string = "3 import android.animation.Animator; \n" +
"4 import android.animation.AnimatorListenerAdapter; \n" +
"5 import android.animation.ValueAnimator; \n" +
"6 import android.app.Activity; \n" +
"7 import android.content.Context; \n" +
"8 import android.content.DialogInterface; \n";
char[] ch = string.toCharArray();
char c ='M';
for(int i=4;i<ch.length;i++){
boolean b1 = false;
boolean b2 = false;
boolean b3 = false;
boolean b4 = false;
c = ch[i];
if((c >= '0' && c <= '9') && (ch[i-1]=='\n')){
b1 = true;
if((ch[i+1] >= '0' && ch[i+1] <= '9'))b2=true;
if((ch[i+2] >= '0' && ch[i+2] <= '9'))b3=true;}
if(b1)ch[i]='Q';
if(b2)ch[i+1]='Q';
if(b3)ch[i+2]='Q';
b1 = false;
b2 = false;
b3 = false;
}
String strings = ch.toString();
strings.replace("Q","");
Log.d("meoww","juy "+strings);
당신이 볼 수 있듯이
는 루프의 나를 위해이 숫자를 제거하려고합니다. 로그는 다음과 같은 출력 보여 :juy [[email protected]
가 나는 그것 아마 사소한 오류를 알고,하지만 나는이 문제를 어떻게 해결할 수 있습니다. 내가 말했듯이, 나는 이것을 for 루프 안에서 약 3600 번해야 할 것이다. 어떤 제안에 대한
덕분에,
이
사용'한 String.valueOf 이것을 대체 할
String.replaceAll ("^\d*\s", " ")
이 코드)' toString() 대신에 – Jens'[C @ 3d03b1f5']와 같은 내용이 표시되면 내용이 아닌 객체의 주소가 표시됩니다 ... 그냥 – bholagabbar
이라고 말하면됩니다. 대신 'String strings = new String (ch); 'String strings = ch.toString(); ' –