stringArrayAddPrefix
在数组里的每个组件前加内容
MEL examples
stringArrayAddPrefix( { “a”, “b”, “c” }, “>” );
,Result:, >a >b >c //
stringArrayAddPrefix( { “a”, “b”, “c” }, “___” );
,Result:, ___a ___b ___c //
string $objs[] = { “a”, “b”, “c” };
stringArrayAddPrefix( $objs, “***” );
print $objs;
***a
***b
***c
stringArrayCatenate
将2个数组合并成1个数组
string $string1[] = {“light1”, “light2”};
string
s
t
r
i
n
g
2
[
]
=
"
l
i
g
h
t
3
"
,
"
l
i
g
h
t
4
"
,
"
l
i
g
h
t
5
"
;
s
t
r
i
n
g
A
r
r
a
y
C
a
t
e
n
a
t
e
(
string2[] = {"light3","light4","light5"}; stringArrayCatenate(
string2[]="light3","light4","light5";stringArrayCatenate(string1, $string2);
// Result: light1 light2 light3 light4 light5 //
stringArrayContains
判断数组里有没有包含弄个组件
string $array1[] = {“item1”, “item2”, “item1”};
// Result: item1 item2 item1 //
int $found = stringArrayContains(“item1”, $array1);
// Result: 1 //
$count = stringArrayContains(“item2”, $array1);
// Result: 1 //
$count = stringArrayContains(“plotz”, $array1);
// Result: 0 //
stringArrayCount
判断数组里有多少个相同的组件
string $array1[] = {“item1”, “item2”, “item1”};
// Result: item1 item2 item1 //
int $count = stringArrayCount(“item1”, $array1);
// Result: 2 //数组里有2个item1
$count = stringArrayCount(“item2”, $array1);
// Result: 1 //
$count = stringArrayCount(“plotz”, $array1);
// Result: 0 //
stringArrayFind
在数组里查找某个组件是从数组里的哪一位开始的
string $array[] = { “item1”, “item2”, “item3” };
// Result: item1 item2 item3 //
int $index = stringArrayFind( “item1”, 0, $array );从第一位的组件开始搜索item1
// Result: 0 //
$index = stringArrayFind( “item1”, 1, $array );如果是从第二位开始搜,那item1就处于-1的位置上
// Result: -1 //
$index = stringArrayFind( “item3”, 4, $array );
// Result: -1 //
$index = stringArrayFind( “blah”, 0, $array );如果数组里没有这个组件 也返回的是-1
// Result: -1 //
stringArrayInsertAtIndex
将新的组件添加到数组中
// Initialize the list
string $list[] = {“item1”, “item3”};
// Result: item1 item3 //
// Insert in the middle of the sequence
stringArrayInsertAtIndex(1, $list, “item2”);
在第2位的位置上添加新组件 item2
// Result: 1 //
print $list;
// Result: item1 item2 item3 //
// Insert before the first element
stringArrayInsertAtIndex(-1, $list, “item4” );
// Result: 0 //
// Insert at (or after) the end of the sequence
stringArrayInsertAtIndex( 10, $list, “item4” );
如果设置的位置大于当前数组的数量,则排在最后
// Result: 1 //
print $list;
// Result: item1 item2 item3 item4 //
// Insert at the beginning of the sequence
stringArrayInsertAtIndex( 0, $list, “item0” );
// Result: 1 //
print $list;
// Result: item0 item1 item2 item3 item4 //
stringArrayIntersector
获取2个数组中相同的组件
string $myIntersector = stringArrayIntersector
;
string $initialArrayA[] = {“aa”, “bb”, “cc”};
string $initialArrayB[] = {“cc”, “dd”, “ff”};
stringArrayIntersector -edit -intersect $initialArrayA $myIntersector;
stringArrayIntersector -edit -intersect $initialArrayB $myIntersector;
stringArrayIntersector -query $myIntersector;
// Result: cc //
stringArrayRemove
移除数组的组件
string $list[] = { “a”, “b”, “c”, “d”, “b”, “e”, “f”, “a”, “g” };
string $items[] = { “a”, “c”, “e”, “g” };
string
d
i
f
f
[
]
=
s
t
r
i
n
g
A
r
r
a
y
R
e
m
o
v
e
(
diff[] = stringArrayRemove(
diff[]=stringArrayRemove(items, $list);
// Result : { b, d, b, f } //
stringArrayRemoveAtIndex
按位置删除组件
string $array1[] = {“item1”, “item2”, “item3”};
// Result: item1 item2 item1 //
stringArrayRemoveAtIndex(1, $array1);
// Result: 1 //删除 $array1里的第二个组件
print $array1;
// Result: item1 item3 //
stringArrayRemoveDuplicates
移除数组中相同的组件
string $list[] = { “d”, “b”, “c”, “c”, “a”, “a”, “b” };
string
s
h
o
r
t
e
r
L
i
s
t
[
]
=
s
t
r
i
n
g
A
r
r
a
y
R
e
m
o
v
e
D
u
p
l
i
c
a
t
e
s
(
shorterList[] = stringArrayRemoveDuplicates(
shorterList[]=stringArrayRemoveDuplicates(list);
// Result : { d, b, c, a } //
stringArrayRemoveExact
删除数组里存在的组件
string $list[] = { “a”, “b”, “a”, “a”, “c” };
string $itemsToRemove[] = { “a”, “c”, “a” };
string
d
i
f
f
[
]
=
s
t
r
i
n
g
A
r
r
a
y
R
e
m
o
v
e
E
x
a
c
t
(
diff[] = stringArrayRemoveExact(
diff[]=stringArrayRemoveExact(itemsToRemove, $list);
// Result : { b, a } //
stringArrayRemovePrefix
移除组件中内容
stringArrayRemovePrefix( { “***a”, “***b”, “***c” }, “***” );
// ,Result:, a b c //
stringArrayRemovePrefix( { “***a”, “+++b”, “—c” }, “***” );
// ,Result:, a +++b —c //
stringArrayRemovePrefix( { “***a”, “”, “—c” }, “***” );
// ,Result:, a —c //
stringArrayToString
将数组变成字符串
stringArrayToString({ “red”, “blue”, “green” }, “”);
// Result: redbluegreen //
stringArrayToString({ "red", "blue", "green" }, ", ");
// Result: red, blue, green //
stringArrayToString({ "user", "directory", "documents", "file" }, "/");
// Result: user/directory/documents/file //
**stringToStringArray
将字符串变成数组**
string $array[];
$array = stringToStringArray("red blue green", " ");
print ("// " + $array[0] + "\n");
print ("// " + $array[1] + "\n");
print ("// " + $array[2] + "\n");
// red
// blue
// green
$array = stringToStringArray("Hey, what's your name?", " ,?");
print ("// " + $array[0] + "\n");
print ("// " + $array[1] + "\n");
print ("// " + $array[2] + "\n");
print ("// " + $array[3] + "\n");
// Hey
// what's
// your
// name
$array = stringToStringArray("/user/directory/documents/file", "/");
print ("// " + $array[0] + "\n");
print ("// " + $array[1] + "\n");
print ("// " + $array[2] + "\n");
print ("// " + $array[3] + "\n");
// user
// directory
// documents
// file