20050110: string join, substring, length

X

Xah Lee

# 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
(e-mail address removed)
http://xahlee.org/PageTwo_dir/more.html
 
J

Jürgen Exner

Xah Lee wrote:
[...]
# perldoc -tf substr

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top