Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2016-10-22 09:35 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (294 votes). Check out past polls.