C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[629] 팁~문자열 처리하는 편리한 함수들 (AnsiString)
크레브 [kkol] 12437 읽음    2007-02-15 21:56
오늘은 빌더 도움말에서 문자열 관련 함수들을 스캔해봤습니다.
지금까지 잘안쓰던 쓸만한 함수들이 꽤 있어서 여기에 올립니다.

-------------------------------------------------------------------------------------------------------------------------------------------
 

 ExtractStrings -->   문자열 파싱하는데 쓰면 편하겠네요

 

근데 단점이 Separators에 넣어준 분리용 문자는 최종 결과에 안나온다는것...

그것까지 포함한 결과를 받고 싶을때는 난감하네요.. 그냥 직접 만들어야지..

 

Category

 

string handling routines (null-terminated)

 

extern PACKAGE int __fastcall ExtractStrings(TSysCharSet Separators, TSysCharSet WhiteSpace, char * Content, TStrings Strings);

 

Description

 

Use ExtractStrings to fill a string list with the substrings of the null-terminated string specified by Content.

 

Separators is a set of characters that are used as delimiters, separating the substrings. Carriage returns, newline characters, and quote characters (single or double) are always treated as separators. Separators are ignored when inside a quoted string until the final end quote. (Note that quoted characters can appear in a quoted string if the quote character is doubled.)

 

WhiteSpace is a set of characters to be ignored when parsing Content if they occur at the beginning of a string.

 

Content is the null-terminated string to parse into substrings.

 

Strings is a string list to which all substrings parsed from Content are added. The string list is not cleared by ExtractStrings, so any strings already in the string list are preserved.

 

ExtractStrings returns the number of strings added to the Strings parameter.

 

 

-------------------------------------------------------------------------------------------------

문자열 검색시 편리함

 

extern PACKAGE char * __fastcall SearchBuf(char *Buf, int BufLen, int SelStart, int SelLength, AnsiString SearchString, TStringSearchOptions Options = TStringSearchOptions() << soDown);

 

Description

 

Call SearchBuf to search for a specified search string within a text buffer.

 

Buf is the text buffer to search.

 

BufLen is the length, in bytes, of Buf.

 

SelStart is the first character of the search when Options indicates a backward search (does not include soDown). The first character in Buf has position 0.

 

SelLength is the number of characters after SelStart that the search begins when Options indicates a forward search (includes soDown).

 

SearchString is the string to find in Buf.

 

Options determines whether the search runs forward (soDown) or backward from SelStart or SelStart+SelLength, whether the search is case sensitive (soMatchCase), and whether the matching string must be a whole word (soWholeWord).

 

If SearchBuf finds a match, it returns a pointer to the first character of the matching string in Buf. If it does not find a match, SearchBuf returns NULL.

-------------------------------------------------------------------------------------------------

 

  문자열 치환 함수 

 

 

extern PACKAGE AnsiString__fastcall AnsiReplaceStr(const AnsiString AText, const AnsiString AFromText, const AnsiString AToText);

 

Description

 

Call AnsiReplaceStr to scan the string specified by AText and replace all occurrences of the string specified by AFromText with the string specified by AToText. Occurrences of AFromText are identify by a case-sensitive comparison. The identification of substrings is not recursive: if the substitution of AToText results in a new match for AFromText, that match is not replaced.

 

 

AnsiReplaceText 대소문자 구별 안합니다.

 

 

 

-----

이것도 비슷한함수인데요 StringReplace는 하나만 바꾸는듯함

 

 

enum SysUtils__93 { rfReplaceAll, rfIgnoreCase };

 

typedef Set  TReplaceFlags;

 

extern PACKAGE AnsiString __fastcall StringReplace(const AnsiString S, const AnsiString OldPattern, const AnsiString NewPattern, TReplaceFlags Flags);

 

Description

 

StringReplace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern. StringReplace assumes that the source string may contain Multibyte characters.

 

S is the source string, whose substrings are changed.

 

OldPattern is the substring to locate and replace with NewPattern.

 

NewPattern is the substring to substitute for occurrences of OldPattern.

 

Flags is a set of flags that govern how StringReplace locates and replaces occurrences of OldPattern. If Flags does not include rfReplaceAll, StringReplace only replaces the first occurrence of OldPattern in S. Otherwise, StringReplace replaces all instances of OldPattern with NewPattern. If the Flags parameter includes rfIgnoreCase, The comparison operation is case insensitive.

 

 

-------------------------------------------------------------------------------------------------

 

 

 

 파일 이름에서 마지막 확장자  체크 같은것 할때 쓰면 편할듯..

 

extern PACKAGE AnsiString__fastcall RightStr(const AnsiString AText, int ACount);

 

Description

 

RightStr returns the trailing characters of AText up to a length of ACount characters. Thus, for example,

 

RightStr("Programmer", 7)

 

returns the string

 

"grammer"

-------------------------------------------------------------------------------------------------

 

 

 

장성호 [nasilso]   2009-09-17 14:20 X
다음 링크에 ExtractStrings 수정 버젼이 있습니다.
그냥 공백같은 문제를 구분자로 판단하지 않는 버젼입니다.

http://www.delmadang.com/community/bbs_view.asp?bbsNo=3&bbsCat=0&st=C&keyword=TStringList&indx=404017&keyword1=TStringList&keyword2=&page=1

+ -

관련 글 리스트
629 팁~문자열 처리하는 편리한 함수들 (AnsiString) 크레브 12437 2007/02/15
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.