
Gabriele
Novice
Mar 7, 2016, 9:20 AM
Post #1 of 3
(1738 views)
|
Highlight substring in string
|
Can't Post
|
|
Hi, I have a CGI script that basically capture a string (a DNA sequence) which the user types in the search box of my interface page. In my cgi script i want to take that string and analyze it for the presence of a substring (gaatcc); I want to print out my full string with these substrings highlighted in bold. My code below does half of the job; but for some reasons it only highlight the first occurence of the substring; i.e. if there is more than 1 gaatcc, it highlights the first one only. My code below:
my $length = length($sequence); for (my $i=0; $i < $length; $i++) { if (substr($sequence, $i, 6) eq "gaatcc") { substr($sequence, $i, 6) = '<b>' . substr($sequence, $i, 6) . '</b>'; } } print "<p>$sequence</p>"; Any help?
(This post was edited by Gabriele on Mar 7, 2016, 9:54 AM)
|