我在这里使用代码 - 如何在PHP项目中找到未使用的函数(下面再现),只是修改到我的位置的路径,其行为如下:
root@server [/var/www]# php see_unused_code.php
T_STRING
Run Code Online (Sandbox Code Playgroud)
使用的代码是:
<?php
$functions = array();
$path = "/path/to/my/php/project";
define_dir($path, $functions);
reference_dir($path, $functions);
echo
"<table>" .
"<tr>" .
"<th>Name</th>" .
"<th>Defined</th>" .
"<th>Referenced</th>" .
"</tr>";
foreach ($functions as $name => $value) {
echo
"<tr>" .
"<td>" . htmlentities($name) . "</td>" .
"<td>" . (isset($value[0]) ? count($value[0]) : "-") . "</td>" .
"<td>" . (isset($value[1]) ? count($value[1]) : "-") . "</td>" .
"</tr>";
}
echo "</table>";
function define_dir($path, &$functions) {
if ($dir = …Run Code Online (Sandbox Code Playgroud) 我用tstringlist做了一个非常简单的日志.我把它写到文件:
pLog.SaveToFile(FileName);
Run Code Online (Sandbox Code Playgroud)
某处有一个错误,我的电脑关机了.之后,我找不到我的日志文件.可能该文件以asych模式保存.还有一种方法可以等待写入继续执行吗?
谢谢,Alberto
:)
首先,我的代码
procedure TForm1.Button3Click(Sender: TObject);
var tempId,i:integer;
begin
tempId:=strtoint(edit5.Text);
plik:=TStringList.Create;
plik.LoadFromFile('.\klienci\'+linia_klient[id+1]+'.txt');
if (plik.Count=1) then
begin
label6.Caption:='then';
if (tempId=StrToInt(plik[0])) then
begin
Label6.Caption:='Zwrócono';
plik.Delete(0);
end
end
else
for i:=0 to plik.Count-2 do
begin
if (tempId=StrToInt(plik[i])) then
begin
Label6.Caption:='Zwrócono';
plik.Delete(i);
end;
end;
plik.SaveToFile('.\klienci\'+linia_klient[id+1]+'.txt');
plik.Free;
end;
Run Code Online (Sandbox Code Playgroud)
for i:=0 to plik.Count-2 do我可以删除任何元素但不能删除.for i:=0 to plik.Count-1 do我可以删除任何元素而不是从头开始.因为否则List索引越界.怎么样?如何安全搜索和删除TStringList中的元素?
我正在实现本地缓存以加速DNS查找(IP->主机名).缓存从CSV文件("1.1.1.1host.example.com")加载到具有两个字段的TStringList中:
TStringList[0] := IPAddress;
TStringList[1] := HostName;
Run Code Online (Sandbox Code Playgroud)
因为我将通过IP查询TStringList,所以我想要对第一个字段进行排序:
TStringList.sorted := True;
Run Code Online (Sandbox Code Playgroud)
这会照顾它,以便我可以更快找到
IPResolved:=TStringList[TStringList.IndexOf('1.1.1.1'),1];
Run Code Online (Sandbox Code Playgroud)
?
谢谢!
我有一个TStringList,它被排序并包含唯一的文件名.该列表可以是任何大小(因此它可以是数十万个条目).我想检查是否有任何条目以特定字符串开头(即文件是否在子文件夹中).串行扫描列表并使用StartsText很容易,但这不是一个理想的解决方案.
使用TStringList.Find()代码作为起点,我创建了一个我认为是解决方案的函数,但我想确定.不要担心以下不是类的成员(FList是被搜索的TStringList实例),StartsFilename的工作方式与StartsText相同:
function ShortcutFind(const S: string): Boolean;
var
L, H, I, C: Integer;
begin
Result := False;
L := 0;
H := FList.Count - 1;
while L <= H do begin
I := (L + H) shr 1;
if TFilenameUtils.StartsFilename(FList[I], aFolder) then begin
Result:=TRUE;
Exit;
end;
C := FList.CompareStrings(FList[I], S);
if C < 0 then
L := I + 1
else begin
H := I - 1;
if C = 0 then begin
Result := True;
if FList.Duplicates <> dupAccept …Run Code Online (Sandbox Code Playgroud) 我有一个TStringList有很多字符串的字符串.
我现在要做的是TStringList根据它们所在的列来对某些值进行排序TStringList.
例如.
adsfoiadjfoaidjfoaidfjo BABABA asdfsd 0101010 skfjlgjljkglsdkgjasaasd BABABA dafdff 0419299 asdaksdjakbkj3409560295 BABABA kjfhan 0923858 dsdddsdasdadasdasdasdgg BABABA dafdff 0419299 45645654654654654654666 BABABA dafdff 0489421 dsdddsdasdadasdasdasdgg CACACA dafdff 0419299
正如您所看到的那样,第二行和第四行具有相同的值BABABA以及行尾的相同数字,第五行具有相同的BABABA但不是相同的数字.第六行具有相同的数字但不是相同的BABABA.
我想要对它们进行排序的正确方法是
adsfoiadjfoaidjfoaidfjo BABABA asdfsd 0101010 skfjlgjljkglsdkgjasaasd BABABA dafdff 0419299 dsdddsdasdadasdasdasdgg BABABA dafdff 0419299 45645654654654654654666 BABABA dafdff 0489421 asdaksdjakbkj3409560295 BABABA kjfhan 0923858 dsdddsdasdadasdasdasdgg CACACA dafdff 0419299
我想要的是最重要的是在BABABA(第25-30栏)之后排序,如果数字,数字也匹配.如果数字不匹配,它应该在BABABA之后排序,如果没有排序,它可以以任何方式排序.
我有一个我在FormCreate上创建的TStringList
ScriptList := TStringList.Create;
Run Code Online (Sandbox Code Playgroud)
在将字符串加载到列表中后,在我的程序中的另一个函数中,我有以下代码
ScriptList.Sorted := True;
ScriptList.Sort;
for i := 0 to ScriptList.Count - 1 do
ShowMessage(ScriptList[i]);
Run Code Online (Sandbox Code Playgroud)
但列表没有排序为什么会这样?
已编辑:填写列表由以下代码完成
function TfrmMain.ScriptsLocate(const aComputer: boolean = False): integer;
var
ScriptPath: string;
TempList: TStringList;
begin
TempList := TStringList.Create;
try
if aComputer = True then
begin
ScriptPath := Folders.DirScripts;
Files.Search(TempList, ScriptPath, '*.logon', False);
ScriptList.AddStrings(TempList);
end
else
begin
if ServerCheck then
begin
ScriptPath := ServerPath + 'scripts_' + Network.ComputerName + '\';
Folders.Validate(ScriptPath);
TempList.Clear;
Files.Search(TempList, ScriptPath, '*.logon', False);
ScriptList.AddStrings(TempList);
Application.ProcessMessages;
ScriptPath := ServerPath + …Run Code Online (Sandbox Code Playgroud) 大家晚上好。
我有一个 StringList 并且每条记录都包含一个多行字符串。
我的字符串列表 [0]:
<li>
Test1
</li>
Run Code Online (Sandbox Code Playgroud)
我的字符串列表 [1]:
<a href="#">
<b>
Test2
</b>
</a>
Run Code Online (Sandbox Code Playgroud)
等等。
如何将这些字符串保存和加载到文件(文本、ini、二进制、记录、savetofile 等)?主要问题是我不能将其保存到文本文件中,但是在回读时,每行都被视为一条新记录,而第一条记录有 3 行,第二条记录有 5 行,依此类推。
您对保存和加载这些字符串的过程有何建议?
我有一个多行字符串,我想从中删除一些行.TMemo组件包含执行此操作所需的代码.
MyMemo:=TMemo.Create(nil);
try
MyMemo.Text:=MyString;
MyMemo.Lines.Delete(x); // lines I want to delete
MyMemo.Lines.Delete(y);
MyString:=MyMemo.Text;
finally
MyMemo.Free;
end;
Run Code Online (Sandbox Code Playgroud)
但是使用可视组件进行基本转换似乎是错误的.有没有不同但同样简单的方法呢?谢谢
我有一个字符串列表,每个字符串看起来都是这样的。
2023/01/30,08:47:27, 0. 7.71,CM212-A2,03,Bad head/nozzle detect,380000,Stage No1, Head No2, Nozzle Postion5, Nozzle No0, (Single Lane), PCB ID: , Bad head/nozzle detectReset
Run Code Online (Sandbox Code Playgroud)
然后我将该字符串添加到另一个带有逗号文本的列表中,并且应该给出如下结果
2023/01/30
08:47:27
0. 7.71
CM212-A2
03
Bad head/nozzle detect
Run Code Online (Sandbox Code Playgroud)
相反,它返回
2023/01/30
08:47:27
0.
7.71
CM212-A2
03
Bad
head/nozzle
detect
Run Code Online (Sandbox Code Playgroud)
看起来它会像我想要的那样为每个逗号创建一个新字符串,但也会为我不想要的每个空格创建一个新字符串。
添加代码以防万一需要。
procedure TForm4.Button1Click(Sender: TObject);
var
datalist : tstringlist;
eventlist : tstringlist;
i,x: Integer;
filename : string;
Event : array[1..200] of TEvent;
begin
datalist := tstringlist.Create;
eventlist := tstringlist.Create;
X := 1;
//get latest file
filename := getlastmodifiedfilename('C:\Users\tngmorse\Desktop\LockHeads\Win32\Debug\');
//end …Run Code Online (Sandbox Code Playgroud)