string class 에서 ltrim,rtrim,trim 을 구현하고 싶습니다.
글쓴이: linuxqna / 작성시간: 수, 2003/04/02 - 5:39오후
요즘 C++을 쓰고 있는데
C에서는 pointer를 이용해서 ltrim, rtrim, trim 을 구현해서 쓰곤했는데
혹시 C++의 string class 에서 이걸 쉽게 구현할 방법이 있을까요 ?
string name(" KLDP BBS ");
요기서 name의 앞뒤의 white space를 잘라내고 싶습니다.
string class의 member function을 조합하면 될것 같기도 한데.
아무튼 조언 부탁드립니다.
Forums:
...
단순하게 사용하시던 방법으로 하셔도 될텐데요. c_str().
좀 더 깔끔하게는 iterator로 검색하면서 string::erase()랑해서 지우시는걸로 구현하셔도 될듯.
## 아래에 달린 링크보니 저렇게 우아하게도!^^;
----
The future is here. It's just not widely distributed yet.
- William Gibson
다음 링크 참고...
http://www.borlandforum.com/impboard/impboard.dll?action=read&db=cpp_tip&no=1
워닝 없애기 ㅎ
출처는 위의 링크 ( http://www.borlandforum.com/impboard/impboard.dll?action=read&db=cpp_tip&no=1 ) 입니다
int로 선언되어있는 position용 변수 n의 type을 string::size_type로 바꾸었습니다. find()의 리턴 형이 저것 맞지요? :)
[quote="lacovnk"]int로 선언되어있는 position용 변
네. int를 쓰면 오동작할 수도 있어요.
비슷하지만 string::size_type 대신 iterator를 쓰는 방법입니다.
boost 라이브러리를 참고하세요.http://boost.org/
boost 라이브러리를 참고하세요.
http://boost.org/doc/html/string_algo/usage.html#id1290955
댓글 달기