이번엔 공백 처리 함수들이다. 로그인할때 아이디 처리라던지에 써먹은 기억이 있다 : )


#include <cstdio>

#include <string>

#include <boost/algorithm/string.hpp>

 

using namespace boost;

using namespace std;

 

int _tmain(int argc, _TCHAR* argv[])

{

        string str1 = "   I love Lyn!      ";

        string str2;

        trim(str1); //양옆의공백을다제거한다.

        printf("trim : %s\n", str1.c_str());

 

        str1 = "   I love Lyn       ";

        str2 = trim_copy(str1); //양옆의공백을다제거하되원본을변경하지않고새로운문자열을리턴

        printf("trim_copy : %s, %s\n", str1.c_str(), str2.c_str());

 

        str1 = "#######   I love Lyn       #######";

        trim_if(str1,is_any_of("#")); //제거할문자를직접지정해서제거한다.

        printf("trim_if-1 : %s\n", str1.c_str());

 

        str1 = "!@#!@#I love Lyn!@#!@#";

        trim_if(str1,is_any_of("!@#")); //제거할문자열의길이에는제한이없다!

        printf("trim_if-2 : %s\n", str1.c_str());

 

        str1 = "   I love Lyn       ";

        trim_left(str1); //왼쪽의공백을제거한다.

        printf("trim_left : %s\n", str1.c_str());

       

        //물론trim_left_copy, trim_left_if, trim_right, trim_right_copy, trim_right_copy_if 등등.. 있을함수는다있다.

        //여기서는몇가지만소가했지만네이밍규칙을보면다알수있을수준이다.

        return 0;

}

 

조회 수 :
14372
등록일 :
2009.05.20
10:42:14 (*.149.217.155)
엮인글 :
http://www.lunapiece.net/3814/f12/trackback
게시글 주소 :
http://www.lunapiece.net/3814
문서 첨부 제한 : 0Byte/ 10.00MB
파일 제한 크기 : 10.00MB (허용한 확장자만 첨부할 수 있습니다.(관리자는 제외) : *.*)
옵션 :
:
:
:
:
List of Articles
번호 제목 글쓴이 날짜 조회 수
» [Boost 살펴보기] 7. String Algorithm2 Lyn 2009-05-20 14372
12 [Boost 살펴보기] 6. String Algorithm1 Lyn 2009-05-12 15372
11 [Boost 살펴보기] 5. lexical_cast file Lyn 2009-05-12 15659
10 [Boost 살펴보기] 4. multi_array Lyn 2009-05-11 14895
9 [Boost 살펴보기] 3. timer Lyn 2009-05-11 14903
8 [Boost 살펴보기] 2. any Lyn 2009-05-11 13844
7 [Boost 살펴보기] 1. pool file Lyn 2009-05-11 14454
6 프로그래밍 대회 알고리즘 파트 문제 [2] secret Lyn 2008-11-21 15485
5 컨테이너가 파괴될 때 소유한 객체 자동으로 파괴하기 Lyn 2008-10-22 13208
4 [TR1 살펴보기] 3. UnOrdered Containers Lyn 2008-10-05 14315
3 [TR1 살펴보기] 2. Array Lyn 2008-10-05 14255
2 [TR1 살펴보기] 1. Random Lyn 2008-10-05 14695
1 Delphi 2009 Generic 살펴보기 [1] Lyn 2008-09-29 12695

SITE LOGIN :)