String question

Discussion in 'Perl Misc' started by GeekX, Jul 1, 2005.

  1. GeekX

    GeekX Guest

    How to select substring?

    from: "abcde *:; fghijkl mno pqrstuwxyz"

    I want: everything between and icluding "cde" and "stu".
    That is: "cde *:; fghijkl mno pqrstu"

    Thanks!
     
    GeekX, Jul 1, 2005
    #1
    1. Advertising

  2. GeekX <> wrote in news:da494n$ivl$2@phys-
    news1.kolumbus.fi:

    > How to select substring?
    >
    > from: "abcde *:; fghijkl mno pqrstuwxyz"
    >
    > I want: everything between and icluding "cde" and "stu".
    > That is: "cde *:; fghijkl mno pqrstu"


    Please read the posting guidelines for this group. They contain
    invaluable information on how you can help yourself, and help others
    help you.

    perldoc -f index
    perldoc -f substr

    or, you can use a capturing regex match.

    #!/usr/bin/perl

    use strict;
    use warnings;

    my $s = "abcde *:; fghijkl mno pqrstuwxyz";
    my $start = index $s, 'c';
    my $end = index $s, 'w';
    my $r = substr$s, $start, $end - $start;

    print $r."\n";

    if($s =~ /(c.+u)/ ) {
    print $1."\n";
    }

    __END__

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Jul 1, 2005
    #2
    1. Advertising

  3. Gunnar Hjalmarsson, Jul 1, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mladen Adamovic
    Replies:
    0
    Views:
    777
    Mladen Adamovic
    Dec 4, 2003
  2. Mladen Adamovic
    Replies:
    3
    Views:
    14,780
    Mladen Adamovic
    Dec 5, 2003
  3. Matt
    Replies:
    3
    Views:
    553
    Tor Iver Wilhelmsen
    Sep 17, 2004
  4. Bruce Sam
    Replies:
    15
    Views:
    8,066
    John C. Bollinger
    Nov 19, 2004
  5. =?Utf-8?B?UmFqZXNoIHNvbmk=?=

    'System.String[]' from its string representation 'String[] Array'

    =?Utf-8?B?UmFqZXNoIHNvbmk=?=, May 4, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,820
    =?Utf-8?B?UmFqZXNoIHNvbmk=?=
    May 4, 2006
Loading...

Share This Page