20050110: string join, substring, length

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xah Lee

    #1

    20050110: string join, substring, length

    # strings can be joined by +.
    print "this" + " that"

    # string can be multiplied
    print "this" *5

    # substring extraction is done by appending a bracket
    # with begin and ending index
    a="this and that"
    print a[3:6]

    # index can be negative,
    # and sometimes out of bound will just mean length of the string
    print a[3:-2]

    # length of the string is len()
    print len(a)

    -------------------------

    # in perl, string join is done with a dot.
    $astr= "this" . "that";

    # string repeatition is done with an x
    print $astr x 5;

    # string extraction is done with substr()
    # for more about sbstr(), see verbose
    # perldoc -tf substr

    # length of string is length();
    print length $astr;
    Xah
    xah@xahlee.org


  • Jürgen Exner

    #2
    Re: 20050110: string join, substring, length

    Xah Lee wrote:
    [...][color=blue]
    > # perldoc -tf substr[/color]

    Is there a specific reason why you are 'ugly-printing' the doc pages?
    From 'perldoc perldoc':

    -t text output
    Display docs using plain text converter, instead of nroff. This may
    be faster, but it won't look as nice.

    jue


    Comment

    Working...