문자열이 있다고 가정 해 봅시다. "\\ u2026". 그리고 그것을 스칼라에서 유니 코드를 출력하기 위해 "\ u2026"으로 바꾸고 싶습니다. 그렇게 할 수있는 방법이 있습니까? 시간 내 주셔서 감사합니다.스칼라에서 \ to 로 변환
편집 : 내가 명확하게 설명해주세요. 어떤 상황으로 인해, 나는 같은 문자열을 가지고, 인쇄 :
다음 문자는 유니 코드에 있습니다 : "\\ U2026 문자에 이어 유니 코드에"\ U2026
, 나는 편집 할 그것은이 인쇄되도록 :
다음 문자는 유니 코드에 있습니다 ...
이 답변 주셔서 감사합니다. 이것이 제가 끝내 준 것입니다. String.replace 방법을 사용하도록 요청으로 질문에
def FixString(string: String) : String = {
var newString = string;
// Find the 1st problematic string
var start = string.indexOf("\\u");
while(start != -1) {
// Extract the problematic string
val end = start + 6;
val wrongString = string.substring(start,end);
// Convert to unicode
val hexCode = wrongString.substring(2);
val intCode = Integer.parseInt(hexCode, 16);
val finalString = new String(Character.toChars(intCode));
// Replace
newString = string.replace(wrongString,finalString);
// Find next problematic string
start = string.indexOf("\\u", end);
}
return newString;
}
이중 백 슬래시를 제거 하시겠습니까? –