Re: Rindex used to find end of a string
- From: Ben Morrow <ben@xxxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 17:44:48 +0000
Quoth "Paul.Lee.1971" <Paul.Lee.1971@xxxxxxxxxxxxxx>:
Hi all,
I have a sequence of strings, for instance
"Hello, World "
"My First Perl Test "
"Exit(0) "
- as you can see, the strings are all different lengths. Is there a
way to use rindex to find out the last non-whitespace character in the
string?
Not easily. For a task like this you want a regex. The index of the last
non-whitespace character in a string $str can be found with
$str =~ /(\s*)$/ && length($str) - length($1) - 1;
....
I'd like to be able to use a general function to return
"Hello, World", "My First Perl Test" and "Exit(0).
....but if you just want to remove it you'd be better off doing that in
one step:
$str =~ s/\s*$//;
You need to read up on basic Perl operations: I would recommend you get
a good book.
Ben
--
Raise your hand if you're invulnerable.
[ben@xxxxxxxxxxxx]
.
- References:
- Rindex used to find end of a string
- From: Paul.Lee.1971
- Rindex used to find end of a string
- Prev by Date: Perl and MySQL
- Next by Date: Re: Perl and MySQL
- Previous by thread: Rindex used to find end of a string
- Next by thread: Parent process unable to read messages from child process
- Index(es):
Relevant Pages
|