【轉】Maya Mel – Search String in String

轉自:http://schiho.com/?p=179this

Hi,
this is a little script which returns a 0 or 1 if the searched text is in a string. Compared with the match function in mel, this one returns 1 or 0, which is more convenient for my opinion. Furthermore somtimes i get really weired results with the match func().code

global proc int ySearch(string $searchWord, string $searchInText){ip

string $longText = $searchInText;
string $shortText = $searchWord;
int $i = 0;
int $j = 0;
string $searchText = 「」;
for($i = 1; $i <= (size($longText)-1); $i++){
for($j = $i; $j <= size($longText); $j++){
$searchText = substring($longText, $i, $j);
//print(」 i 」 + $i + 」 」 + $j + 」 j \n」);
if ($searchText == $shortText){
return 1;
//print(「drinnen」);
}get

}string

}
return 0;
}it

//Usage:
ySearch(「where is schiho today?」, 「schiho」);io

//Result: 1function

相關文章
相關標籤/搜索