Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: indexing in strings

by roboticus (Chancellor)
on Nov 24, 2012 at 14:02 UTC ( #1005375=note: print w/replies, xml ) Need Help??

in reply to indexing in strings

Yes, index looks like a fine way to find the small string inside the big one. I don't know the rule for adding 'O' and 'I' to your string, but index tells you how many bytes from the front the small string is located, so given that value and your rule for adding 'I' and 'O', it should be straightforward. Don't forget that a simple way to generate a repeated string of characters is the x operator:

my $text = 'The quick red fox jumped over the lazy brown dog'; my $search = 'quick'; my $location = index($text, $search); if ($location < 0) { print "$search not found!\n"; } else { print "$search found $location bytes from the front" . ("!"x$locat +ion), "\n"; }

(Note: totally untested)


When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: indexing in strings
by Anonymous Monk on Nov 24, 2012 at 14:12 UTC
    Thanks so much, I just started looikg at it :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005375]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2018-05-27 01:55 GMT
Find Nodes?
    Voting Booth?