참고 사항 및 기타/나중에 볼 에러 해결 모음

Why can't I divide by dots in string.split in Java?

이유는 .(dot)는 정규식 예약어이기 때문이다.

\n(개행문자)를 제외한 모든 문자를 의미한다.

 

모든 문자를 split하면서 모두 없어진 것

그래서 .을 기준으로 나누고 싶다면

\\.

으로 나눠야 한다.

 

String[] stringArr = new String[3];
		
		String s = "LeetCode@LeetCode.com";
		String[] temp = s.split("@");
		stringArr[0] = temp[0];
		
		temp = temp[1].split("\\.");
		stringArr[1] = temp[0];
		stringArr[2] = temp[1];

 

출처

marobiana.tistory.com/137

 

Java String split 또는 replace 할 때 .(Dot, 점) 안되는 현상

내가 split 하려고 했던 문자열이 아래와 같다고 하면,  String text = "aaa.111"; . (dot)로 split을 하려고 했다. String[] result = text.split("."); System.out.println(result.length); 결과는 몇일까? ...

marobiana.tistory.com