Perl/문자열 페이지의 소스 보기
마지막으로 [b]
-- Loading page list... --
내용출력
로그인[l]
Diary
[f]
최근변경내역
[r]
페이지목록[i]
횡설수설[2]
게시판[3]
링크
수정할 수 없습니다: Perl/문자열 는 읽기 전용 페이지입니다.
[[Perl]]의 문자열 처리 관련 == # index == 스트링 내에서 최초로 나타나는 서브스트링의 위치
{{{#!vim perl my $stuff = "Howdy world!"; my $where1 = index($stuff, "w"); # $where1 gets 2 my $where2 = index($stuff, "w", $where1 + 1); # $where2 gets 6 - 세번째 인자는 index의 리턴값의 최소값을 명시 my $where3 = index($stuff, "w", $where2 + 1); # $where3 gets -1 (not found) }}} == # rindex == 스트링 내에서 최후로 나타나는 서브스트링의 위치
{{{#!vim perl my $fred = "Yabba dabba doo!"; my $where1 = rindex($fred, "abba"); # $where1 gets 7 my $where2 = rindex($fred, "abba", $where1 - 1); # $where2 gets 1 - 세번째 인자는 rindex의 리턴값의 최대값을 명시 my $where3 = rindex($fred, "abba", $where2 - 1); # $where3 gets -1 }}} == # substr == 특정 위치의 서브스트링 추출
{{{#!vim perl $part = substr($string, $initial_position, $length); my $mineral = substr("Fred J. Flintstone", 8, 5); # gets "Flint" my $rock = substr "Fred J. Flintstone", 13, 1000; # gets "stone" my $pebble = substr "Fred J. Flintstone", 13; # gets "stone" # 길이 생략 }}} 스트링이 lvalue로 주어질 경우는 치환도 가능
{{{#!vim perl my $string = "Hello, world!"; substr($string, 0, 5) = "Goodbye"; # $string is now "Goodbye, world!" # 정규 표현식 바인드 연산도 가능 substr($string, -20) =~ s/fred/barney/g; # 이런 형태로도 사용가능 my $previous_value = substr($string, 0, 5, "Goodbye"); # 리턴값은 치환되기 전의 해당 위치의 서브스트링 }}} == # sprintf == sprintf FORMAT, LIST
== # 기타 == * 스트링 내의 변수치환과 다른 이스케이프 시퀀스들의 적용 순서에 관한 얘기. 스트링과 정규식에서 좀 다르다. ** [http://www.effectiveperlprogramming.com/blog/1496 Understand the order of operations in double quoted contexts | The Effective Perler]
----
---- [[컴퓨터분류]]
Perl/문자열
페이지로 돌아가기 |
다른 수정본 보기