如何将这个字符串检查从PHP转换为AS3?

Hey guys I'm not sure how to write this in AS3, but basically I need to run a check on some strings coming in. If they have BTS or TS in front of their name then do this, else do nothing.

PHP Script:

$theid =$this->uri->segment(3);


if(substr($theid,0,3) =='BTS'){
    $theid = str_replace('BTS', 'TS', $theid);
}
$video =  $this->ecx_model->custom_search_small($theid,'any','reference_id');
if (!theid.indexOf("BTS")) theid = theid.replace(/BTS/g, "TS");