Boris Hoeller: Zeichen zählen .....

Frage:

Ein string lautet "abcdefghijklmnopqrstuvwxyz"

Wie kann man jetzt z.B. in PERL sagen, daß man aus vorgenannten string, nur x Stellen ausgeben kann.

Bsp:
x=10  und newstring=abcdefghij
oder
x=4 und newstring=abcd

y=3 und geht das in ebenso vielen Zeilen?

bonngrüße
Boris

  1. Frage:

    Ein string lautet "abcdefghijklmnopqrstuvwxyz"

    Wie kann man jetzt z.B. in PERL sagen, daß man aus vorgenannten string, nur x Stellen ausgeben kann.

    Hi Boris,

    mit der Funktion substr.

    lt. "Perl in a nutshell":

    substr

    substr string, pos, [n, replacement]

    Extracts and returns a substring n characters long, starting at character position pos, from a given string. If pos is negative, the substring starts that far from the end of the string instead. If n is omitted, everything to the end of the string is returned. If n is negative, the length is calculated to leave that many characters off the end of the string.

    You can use substr() as an lvalue - replacing the delimited substring with a new string - if string is given as an lvalue. You can also specify a replacement string in the fourth parameter to replace the substring. The original extracted substring is still returned.

    By
    Timothy

    1. mit der Funktion substr.

      ...und wegen der syntax: www.perl.com -> documentation -> functions

      cu

      1. mit der Funktion substr.

        ...und wegen der syntax: www.perl.com -> documentation -> functions

        substr string, pos, [n, replacement]

        Hi,

        was hast Du an obiger Syntax auszusetzen???

        Bye
        ein etwas ratloser Timothy

        1. tagchen,

          was hast Du an obiger Syntax auszusetzen???

          müsste das nicht substr ($string, start, anzahl) heissen ??

          1. tagchen,

            was hast Du an obiger Syntax auszusetzen???

            müsste das nicht substr ($string, start, anzahl) heissen ??

            Hi,

            es geht sowohl als auch. Perl ist bekannt dafür, daß es mehr als einen Weg gibt.

            "There is more than one way to do it" - eines der großen Schlagworte (-sätze) der Perl-Community.

            Gruß
            Timothy