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
[322] StrReplace 함수
유영인 [Chris] [cuperido] 7019 읽음    2002-04-04 15:20
stString 문자열에서 stSource문자열을 stTarget문자열으로 변경시켜 줍니다.
UpperCase() 함수가 생각보다 속도가 느려 따로 변수를 잡아 계산하였습니다.

blClassification이 True면 대소문자를 구별하고, False면 구별하지 않습니다.
간단한 함수지만, 없으면 불편하고 만들기에는 귀찮은... --;

String __fastcall TForm1::StrReplace(String stString, String stSource, String stTarget, bool blClassification)
{

 String            stParse = "",
                   stUString = blClassification ? stString : stString.UpperCase(),
                   stUSource = blClassification ? stSource : stSource.UpperCase();
 int               itCount, itSourceLength = stSource.Length();


 for(itCount = 1; itCount <= stString.Length(); itCount ++) {
   if(stUString.SubString(itCount, itSourceLength) == stUSource) {
     stParse += stTarget;
     itCount += stSource.Length() - 1;
    } else {
     stParse += stString.SubString(itCount, 1);
   }
 }


 return(stParse);

}



P.S : 빌더에서는 StringReplace 라는 함수를 쓰면 되네요.. 풀썩... ㅠ_ㅠ
박지훈.임프 [cbuilder]   2007-09-14 15:49 X
StringReplace는 짧은 문자열에는 상관없지만, 상당히 긴 경우에는 성능의 문제가 있습니다. 특히 대소문자 구별을 안하게 옵션을 주면 엄청나게 느려집니다. 그래서 따로 함수를 만들어서 쓰는 것이 낫습니다.

+ -

관련 글 리스트
322 StrReplace 함수 유영인 [Chris] 7019 2002/04/04
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.