5.5.7:Array
Variables
配列(アレイ)変数
A variable can hold
more than a single value. A variable that holds more than
one value is called an array, and each of the values it
holds is called an element. Each element has its own name
(called the element's key).
変数は複数の値を保持することができます。複数の値を保持する変数は配列(アレイ)と呼ばれます。また配列に保持されるあたい一つ一つは要素(エレメント)と呼ばれます。各要素は(要素キーと呼ばれる)それぞれ独自の名前を持っています。
If you think of a
variable as a box with a name, you can think of an array as
a box with compartments inside it. Each compartment is
an element,
and each compartment has a name, or key,
of its own.
変数を名前のついた箱と考えると、配列は要素が入れられた箱の中の仕切りと考えることができます。仕切り各々が要素であり、その仕切りが全て独自の名前、キー、を持っているのです。
You specify an
element of an array variable by using the variable name
along with the element's key. You enclose the key in square
brackets. The key may be either a name or a number. Here's
an example that shows how to put data into one element of
an array:
配列変数の要素は、要素キーと一緒に変数名を使って指定します。要素キーは各カッコ内に記述し、また要素キーは名前か数字かになります。次の例では、配列の一つの要素にデータを入れる方法を示しています:
put
"ABC" into myVariable["myKeyName"]
Note:
If you use a key
that's not a number, you should enclose the key's name in
double quotes whenever you refer to it. This prevents
problems in case there is a variable or reserved word with
the same name.
注釈: 数字以外の要素キーを使う場合、要素キーの名前を参照する時には必ず、要素キーの名前を二重引用符で括って使います。
You can use any element of an array variable in the same
way you use the whole variable: put data into the element
(or before or after it) and find out what data it contains.
In this way, any element of a variable is like a variable
in and of itself.
配列変数の要素のどれでも、全ての変数の使い方と同じ方法で使うことができます:つまり、要素にデータを格納する(或いは、要素の前に、後に格納する)、また配列変数がどんなデータを格納しているかを見つける、等です。この様に見ると、ある変数のどの要素もそれ自身が単独の変数と同じものなのです。
Deleting
Elements of an Array
配列の要素の削除
You use the delete
variable command to remove one element
from an array variable, in the same way you delete a
variable. To delete an element, you specify both the
variable and the element's key:
ある配列変数から一つの要素を削除するのには、変数を削除するのと全く同じ方法で、delete
variableコマンドを使います。要素を削除するには、変数と要素キーの両方を指定します。
delete
variable myVar["myElement"]
This
statement removes the element named "myElement" from the
variable "myVar", but does not delete the other elements in
the array.
上のステイトメントでは、名前が「」の要素を変数「」から削除しています。但し、配列内の他の要素は削除されません。
Listing the
Elements in an Array
配列内の要素の一覧
Tip:
To delete the
contents of an element without deleting the element itself,
put empty
into the element:
秘訣: 要素そのものを削除しないで、一つの要素の内容だけを削除したい場合には、その要素に空のデータ(empty)を入れます。
put
empty into myVar["myElement"]
You
use the keys
function list the
elements in an array variable. The keys
function returns a
list of elements, one per line:
配列変数内の要素の一覧を得るにはkeysファンクションを使います。keysファンクションは要素の一覧を、一行に一つの要素表示として返します。
put
the keys of myArray into listOfElements
Transforming
a List of Data into an Array
リスト形式のデータを配列に変換する
The split
command separates
the parts of a variable into elements of an array. You can
specify what character in the list you want the data to be
split by. The data will be converted into a set of elements
named according to where it is split. For example:
splitコマンドは、変数の構成部分を分離させて配列の要素とします。データ内のどのキャラクタを配列要素の区切りとして使うかを指定します。データは区切りに従って一組の要素名として変換されます。例えば:
put
"A apple,B bottle,C cradle" into myVariable
split
myVariable by comma and space
Will result in the following:
上記のステートメントを実行結果は:
KEY VALUE
A apple
B bottle
C cradle
の様になります。
For more details, see the split
command in the
Transcript Dictionary.
より詳しくは、トランスクリプト辞書のsplitコマンドの項をご覧下さい。
Combining the
Elements of an Array into a List
配列の要素をリスト形式に変換する
The combine
command combines
the elements of the array into a single variable. After the
command is finished executing, the variable specified by
array is no longer an array.
combineコマンドは、配列の要素を単一の変数に変換します。このコマンドの実行後、配列として指定されていた変数は最早配列ではなくなります。
For example:
例えば:
combine
myArray using return
Will combine the contents of the each element of the
original array
so that they appear
on a separate line.
上記のステイトメントは、元々の配列の各要素の内容を変換して、その内容を一行単位で表示させます。
For more information, see the combine
command in the
Transcript Dictionary.
より詳しくは、トランスクリプト辞書のcombineコマンドの項をご覧下さい。
More
Information
より詳しい情報
For more information about using array variables, see the
section on Processing
Text and Data.
配列変数の使い方に関する詳細は、Processing
Text and
Dataセクションをご覧下さい。