프로그래밍/Java
[팁] String에 공백을 지우자..
컴투
2010. 4. 13. 17:15
예) 공백을 가지는 str 스트링 변수 : ab c de f
의 공백을 모드 없애고 싶다며 이렁게 replace 를 이용하세요
이렇게 => str = str.replace(" ", "" ); 사용하면 공백은 모두 사라지고
그러면 결과는 : abcdef 가 됩니다.
public String replace (char oldChar, char newChar)
public String replace (char oldChar, char newChar)
Since: API Level 1
Since: API Level 1
Copies this string replacing occurrences of the specified character with another character.
Copies this string replacing occurrences of the specified character with another character.
Parameters
Parameters
oldChar
the character to replace.
newChar
the replacement character.
Returns
- a new string with occurrences of oldChar replaced by newChar.
oldChar | the character to replace. |
---|---|
newChar | the replacement character. |
Returns
- a new string with occurrences of oldChar replaced by newChar.
반응형