我正在使用 AutoIT 向文本文件添加新条目。但是我需要将其添加到最后一行和倒数第二行之间。
var informationtechnologydivisionmanager = [
{
"name": "Vacant",
"date": "02/6/2017",
"title": "Division Manager",
"mondayAM": "Main Campus AM",
"mondayPM": "Main Campus PM",
"tuesdayAM": "Main Campus AM",
"tuesdayPM": "Main Campus PM",
"wednesdayAM": "Main Campus AM",
"wednesdayPM": "Main Campus PM",
"thursdayAM": "Main Campus AM",
"thursdayPM": "Main Campus PM",
"fridayAM": "Main Campus AM",
"fridayPM": "Main Campus PM",
"saturdayAM": "Main Campus AM",
"saturdayPM": "Main Campus PM"
},
{
"name": "Vacant",
"date": "02/13/2017",
"title": "Division Manager",
"mondayAM": "Main Campus AM",
"mondayPM": "Main Campus PM",
"tuesdayAM": "Main Campus AM",
"tuesdayPM": "Main Campus PM",
"wednesdayAM": "Main Campus AM",
"wednesdayPM": "Main Campus PM",
"thursdayAM": "Main Campus AM",
"thursdayPM": "Main Campus PM",
"fridayAM": "Main Campus AM",
"fridayPM": "Main Campus PM",
"saturdayAM": "Main Campus AM",
"saturdayPM": "Main Campus PM"
},
{
"name": "Vacant",
"date": "02/20/2017",
"title": "Division Manager",
"mondayAM": "Main Campus AM",
"mondayPM": "Main Campus PM",
"tuesdayAM": "Main Campus AM",
"tuesdayPM": "Main Campus PM",
"wednesdayAM": "Main Campus AM",
"wednesdayPM": "Main Campus PM",
"thursdayAM": "Main Campus AM",
"thursdayPM": "Main Campus PM",
"fridayAM": "Main Campus AM",
"fridayPM": "Main Campus PM",
"saturdayAM": "Main Campus AM",
"saturdayPM": "Main Campus PM"
}
];
当他们保存新数据时,我希望能够将其插入到}并且之前];
我对 AutoIT 还很陌生,正在尽力学习它。
答案1
如果你需要在最后一行和倒数第二行你可以使用这个代码:
$aFile = FileReadToArray("text.txt")
$fNew = FileOpen("text.txt",2)
$StringCount = UBound($aFile)-1
$StringToInsert = $StringCount-1 ; number of string from end to insert
for $i=0 to $StringCount
FileWriteLine($fNew, $aFile[$i])
if $i = $StringToInsert then FileWriteLine($fNew, "########New Data Here!###########")
Next
FileClose($fNew)
答案2
这应该可以让你朝着正确的方向前进:
$FileToLoad = "File_Name" ;your file name with the ext
$String = FileRead($FileToLoad)
msgbox(0,"File Content", $String)
$Newinfo = "This is new information"
msgbox(0, "New File Content", StringTrimRight($String, 2) & $Newinfo & @CRLF & "];")