in reply to Substring consisting of all the characters until "character X"?

my $str = "ABXCDEFDGXTGRAAAAAA"; my $start = 5; my $char = "X"; my $end = index($str, $char, $start); my $result = substr($str, $start, $end-$start); print $result, "\n";
What is so complicated/annoying about the code above? If you don't like it, merge lines 4 and 5 into one line - or move them to a sub...

HTH, Rata
  • Comment on Re: Substring consisting of all the characters until "character X"?
  • Download Code