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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|