2010年10月24日 星期日

指令stringArray系列

//stringArrayRemoveAtIndex
//功能:從字串陣列中移除特定的物件

//定義$array1[]
string $array1[] = {"item1", "item2", "item3"};

//移除 $array1[0] //
stringArrayRemoveAtIndex(0, $array1);
print $array1;

// Result: item2 item3 ; item1已經從$array1[]中移除//

stringArrayInsertAtIndex
//功能:從字串陣列中插入特定的物件


//stringArrayInsertAtIndex = {int 第幾順位 ,$ 陣列名稱,"插入字串"};

string $array2[] = {"item1", "item2", "item3"};
// Result: item1 item2 item1 //

stringArrayInsertAtIndex(1, $array2, "new");
// Result: 1 //

//"new"插入成為$array2[1]
print $array2;
// Result: item1 new item2 item3 //

stringArrayContains
// 功能:從字串陣列中檢驗是否存在特定的物件


string $array2[] = {"ggyy", "FLFL", "oooo"};

int $found = stringArrayContains("ggyy", $array3);
// Result: 1 //

$count = stringArrayContains("xxxx", $array3);
// Result: 0 //

//亦可以拿來做判斷式使用

if(stringArrayContains("ggyy",$array3))
{ print "In Side"; }
//In Side

if(!stringArrayContains("xxxx",$array3))
{ print "Out Side"; }
//Out Side

//stringArrayRemove
//功能:從字串陣列中除移另一字串陣列的重複物件


//string[] stringArrayRemove(string[] $A, string[] $B)
//把 陣列$B 中與 陣列$A 重複的字串全部移除

string $list[]  = { "a", "b", "c", "d", "e", "f", "g" };
string $items[] = { "a", "c", "e", "g" };
string $diff[] = stringArrayRemove($items, $list);
// Result : { b, d, f } //

沒有留言: