Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: indexing in strings

by roboticus (Chancellor)
on Nov 24, 2012 at 14:02 UTC ( [id://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)

...roboticus

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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1005375]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found