Everything2
Near Matches
Ignore Exact
Full Text
Everything2

substr

created by avjewe

(idea) by avjewe (7 hr) (print)   ?   (I like it!) Tue May 08 2001 at 21:51:47

A Perl function which takes a substring of a string, returns it, and can replace it with another string.
substr($foo, offset);

returns the last part of the string $foo, beginning at the specified offset. Just like an array subscript, a negative offset counts from the end of the string.

By itself, substr($foo, offset) doesn't actually do anything. There are two ways of applying substr to do useful work.

  1. Use the return value; that is,
    $bar = substr($foo, offset)
    or
    if (substr($foo, offset) =~ /bar/)
  2. Replace the substring with something else; that is,
    substr($foo, offset) = "bar"

substr($foo, offset, length);

As above, but limits the string to a given number of characters.


substr($foo, offset, length, replacement);

Shorthand for 'substr($foo, offset, length) = replacement'


printable version
chaos

Perl last The End replace
Standard Template Library part length work
anything Actually limit replacement
It's Over Shorthand Useful Specify
Offset String return array
negative Subscript function chomp
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
The best nodes of all time:
All your base are belong to us
love conquers all *
Kurt Vonnegut, Jr.
Drinking Alone in the Moonlight
Surviving a long-distance plane flight
Paradoxes of Islamic Fundamentalism
Occam's Revenge
NSC-68
hamburger
nectarine
Mae West
Stephen Biko
Dragon curve
New Writeups
antigravpussy
One fly amongst many(person)
sam512
Moon Base Shackleton, 1978(fiction)
Pavlovna
toy boy(person)
XWiz
tear jerker(review)
Heitah
Anarchy is Order(idea)
jessicaj
July 26, 2008(dream)
Berek
ABBA(person)
devolution
k-hole(place)
Nadine_2
The Sound Of Madness(review)
SwimmingMonkey
Conversations with Fo Fo, the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
antigravpussy
I fall silent, listening. The breadcrumbs are talking about us(person)
This page courtesy of The Everything Development Company