我已将文件中的一些数据加载到三个Unbounded_String类型的数组中,我将其称为Days,Months和Seasons。
这些数组中的每一个都有一个相应的Integer,它记录了数组中的项目数,即。 Days_Total,Months_Total和Seasons_Total。
我想迭代这三个数组,然后输出所有数据,理想情况下是形式的东西(这是伪Ada):
for Count_1 in (Days, Months, Years) loop
for Count_2 in 1 .. (Count_1)_Total loop
Put_Line (Count_1 (Count_2));
end loop;
end loop;
而我目前正在做的事情是
for Count in 1 .. Days_Total loop
Put_Line (Days (Count));
end loop;
for Count in 1 .. Months_Total loop
Put_Line (Months (Count));
end loop;
for Count in 1 .. Seasons_Total loop
Put_Line (Seasons (Count));
end loop;
我猜我需要使用访问类型,但目前我无法绕过它。完整的示例程序是(load_data_example.adb):
with Ada.Strings.Unbounded, Text_IO, Ustrings;
use Ada.Strings.Unbounded, Text_IO, Ustrings;
procedure Load_Data_Example is
Max_Items : Constant := 12;
Datafile : File_Type;
Datafile_Name : String := "datafile";
type Small_String_Array is array (1 .. Max_Items)
of Unbounded_String;
Days, Months, Seasons : Small_String_Array;
Days_Total, Months_Total : Integer := 0;
Seasons_Total : Integer := 0;
Datafile_Len, Datafile_Skip : Integer := 0;
Line_Count, Lines_Expected : Integer := 0;
Data_Index, Input_Len : Integer := 0;
Input : Unbounded_String;
begin
Open (Datafile, In_File, Datafile_Name);
while (not End_Of_File (Datafile)) loop
Get_Line (Datafile, Input);
Datafile_Len := Datafile_Len + 1;
Input_Len := Length (Input);
if Line_Count <= (Lines_Expected - 1) then
Line_Count := Line_Count + 1;
end if;
if Datafile_Len = (Datafile_Skip + 1) then
Line_Count := 0;
Data_Index := Data_Index + 1;
Lines_Expected := Integer'Value (To_String (Input));
Datafile_Skip := Datafile_Skip + Lines_Expected + 1;
else
case Data_Index is
when 1 => Days (Line_Count) := Input;
Days_Total := Days_Total + 1;
when 2 => Months (Line_Count) := Input;
Months_Total := Months_Total + 1;
when 3 => Seasons (Line_Count) := Input;
Seasons_Total := Seasons_Total + 1;
when others => null;
end case;
end if;
end loop;
Close (Datafile);
for Count in 1 .. Days_Total loop
Put_Line (Days (Count));
end loop;
for Count in 1 .. Months_Total loop
Put_Line (Months (Count));
end loop;
for Count in 1 .. Seasons_Total loop
Put_Line (Seasons (Count));
end loop;
end Load_Data_Example;
数据文件是:
3
Monday
Tuesday
Friday
4
April
June
August
September
2
Spring
Winter
任何提示都会非常感激。
答案 0 :(得分:4)
一种方法:收集记录中每个案例的所有内容,并构建一系列可以排序的记录。
$('#block_accessibility_textresize #block_accessibility_dec').trigger("click");
答案 1 :(得分:3)
扩展Brian的答案:在Ada 2012中,您有容器可以实现您使用的有界向量。您可以使用以下内容代替自己递增和检查总数:
username = "user",
password = "test@1453",
auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
var headers = {
'X-CSRF-TOKEN':'aaaaaa-bbbbbb-1235-ws12-23232jfnfh45',
'Content-Type':'application/json',
"Authorization" : auth
}
var body = {
"flowUuid":"ws123-sed34-2345-ff45-d3f5drfvd331a",
"logLevel": "EXTENDED",
"inputs":
{
"SourceMachine":"10.20.30.40",
"DestinationIP":"abc.domain.com"
}
}
url= 'https://xxx-xxxx-aa.domian.com:8443/aa/rest/v2/executions/',
request({
url: url,
body: body,
json: true,
method:'POST',
headers: headers,
rejectUnauthorized: false,
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
console.log(body)
}
else {
console.log("error: " + error)
console.log("response.statusCode: " + response.statusCode)
console.log("response.statusText: " + response.statusText)
}
})