티스토리 뷰

Code/Study

[PerlNET] Regex (Perl C# Mix)

Hide Code 2008. 11. 9. 04:05

Perl_Regex.zip

Regex.pm

package MixPerl::Regex;

use strict;

use namespace "System";

use PerlNET qw(AUTOCALL);


#Constructor

=for interface

    [interface: pure]

    static Regex();

=cut


#Methods

=for interface

    static string Replace(str SourceString, str FindPattern, str ReplacePattern);

    static string Replaceg(str SourceString, str FindPattern, str ReplacePattern);

    static string Replacegi(str SourceString, str FindPattern, str ReplacePattern);

=cut


#Constructor

sub new

{

    my $class = shift;

    my $self = bless {}, $class;

    return $self;

}


#Methods

sub Replace

{

    my ($source, $find, $replace) = @_;

    $source =~ s/$find/$replace/;

    return $source;

}


sub Replaceg

{

    my ($source, $find, $replace) = @_;

    $source =~ s/$find/$replace/g;

    return $source;

}


sub Replacegi

{

    my ($source, $find, $replace) = @_;

    $source =~ s/$find/$replace/gi;

    return $source;

}




Program.cs

using System;


namespace TestConsole

{

    class Program

    {

        static void Main(string[] args)

        {

            string line;

            line = MixPerl.Regex.Replaceg("abcB", "b", "x");

            Console.WriteLine(line);

            line = MixPerl.Regex.Replacegi("abcB", "b", "x");

            Console.WriteLine(line);

        }

    }

}



'Code > Study' 카테고리의 다른 글

[AutoHotkey] SetTimer & PostMessage  (0) 2010.04.18
[Perl] Cocoa (pl pm sample)  (0) 2008.11.09
[PerlNET] CIty (Mix Perl & C#)  (0) 2008.11.09
[Perl] BeeConverter (Convert HTML Entity to Unicode Character)  (0) 2008.11.09
[C/C++ vs C#] static (1)  (0) 2008.07.16
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함