2016-10-26 7 views
2

는 :불량배의 문자열에서 공백을 제거하는 방법은 무엇입니까? 이 같은 비열한 문자열이있을 때

"\n\tThis is a specification of a toy Transaction.\n\tVia a transaction money 
can be transfered between two accounts\n" 

또는

 This is a specification of a toy Transaction. 
     Via a transaction money can be transfered between two accounts 

어떻게 문자열의 중간에 공백을 제거 할 수 있습니까?

내 솔루션은 이제 '\ n', '\ t'및 '\ r'을 대체하는 함수를 호출하는 것이지만 지속 가능한 솔루션처럼 보이지 않습니다. 또한 trim 함수는 처음과 끝 부분의 공백 만 제거합니다.

답변

1
visit (x) { 
    case /[\t\n]/ => "" 
}