delphi怎么获取字符串之间多个字符内容? delphi 如何循环获取网页源码中两个字符串之间的内容,并写入数组
function GetStr(Str,StrBegin,StrEnd,strxunhuan:string;Isxunhuan :Boolean = false):string;
str 全部文本
StrBegin :开始文本
StrEnd :结束文本
返回 :开始文本和结束文本之间的文本内容
isxunhuan(数组) : false(默认)的话不循环获取,true的话循环获取 (可不输入)
这类任务建议使用正则表达式来完成。
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R dfm}
procedure StrSplite(AStr,ASBegin,ASEnd:string;AStrings:TStrings;AIsXunHun:Boolean=True);
var
iB,iE:Integer;
s:string;
begin
iB:=Pos(ASBegin,AStr);
if iB>0 then
begin
iE:=Pos(ASEnd,AStr);
if iE>0 then
begin
iB:=iB+length(ASBegin);
s:=Copy(AStr,iB,iE-iB);
AStringsAdd(s);
if AIsXunHun then
begin
AStr:=Copy(AStr,iE+length(ASEnd),length(AStr));
StrSplite(AStr,ASBegin,ASEnd,AStrings,AIsXunHun);
end;
end;
end;
end;
procedure TForm1Button1Click(Sender: TObject);
begin
Memo2Clear;
StrSplite(Memo1Text,edit1Text,edit2Text,Memo2Lines,True);
end;
在一堆字符串中,获取两个字符串之间的内容呢?
比如这个么一个字符串 IndexOf——定位字符串中第一次出现某个给定字符串的位置 PadLeft和PadRight——在字符串的开始和结尾用指定的字符填充字符串 ToLower和ToUpper把字符串转换为小写或大写形式 Trim——删除首尾空白 StringReplace——用指定的字符替换字符串中的指定字符。
java怎么获取字符串中第i个字符
截取#之前的字符串
String str = "sdfs#d";
strsubstring(0, strindexOf("#"));
输出的结果为:sdfs
indexOf返回的索引也是从0开始的,所以indexOf("#") = 4。
java中的substring的第一个参数的索引是从0开始,而第二个参数是从1开始
java 怎么获取字符之间的字符串
大概的思路是:
1、使用indexOf获取两个字符串的索引位置。
2、使用subString截取两个字符之间的字符串,参数来源于上面取到的两个索引位置。
python怎么获取字符串有多少个字符
>>> str1 = "1234567990">>> len(str1)10>>> 使用内置的len()函数。
c++中获取字符串首个字符的方法
char string1="my test string!"
char c1=string1[0];
c1就是string1的首个字符。
Java中怎么获取字符串里面的单个字符?
方法有很多种。
随便一种:
String a= "中国人";
char b=acharAt(0);
Systemoutprintln(b);
如何获取字符串中的一个字符c++
可以用索引的吧,string 对象 str="hello world!" str[1]='e'
VB中如何获取字符串取最前面的3个字符和最后3个字符
Private Sub Command1_Click()
a = Left(Text1Text, 3)
b = Right(Text1Text, 3)
End Sub
求教awk两个字符之间截取字符串的方法
假设有字符串:
str="abcdefg"
要截取c和f之间的字符串,得到de。
可以用split函数,以c和f为分隔符,将字符串分割,取分割后的第二个字段。
echo "$str" | awk '{split($0,a,"[cf]");print a[2]}'
另一种方法,也可以分别计算出c和f在字符串中的位置,然后根据截取字符串的起始位置(c的位置+1)和截取长度(f的位置-c的位置-1),用substr函数来得到截取后的字符串。
echo "$str" | awk '{a=index($0,"c");b=index($0,"f");print substr($0,a+1,b-a-1)}'
sed也可以做:
echo "$str" | sed -r 's/c()f/\1/'
使用下面的方法
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
SystemBasicInformation = 0;
SystemPerformanceInformation = 2;
SystemTimeInformation = 3;
type
TPDWord = ^DWORD;
TSystem_Basic_Information = packed record
dwUnknown1: DWORD;
uKeMaximumIncrement: ULONG;
uPageSize: ULONG;
uMmNumberOfPhysicalPages: ULONG;
uMmLowestPhysicalPage: ULONG;
uMmHighestPhysicalPage: ULONG;
uAllocationGranularity: ULONG;
pLowestUserAddress: Pointer;
pMmHighestUserAddress: Pointer;
uKeActiveProcessors: ULONG;
bKeNumberProcessors: byte;
bUnknown2: byte;
wUnknown3: word;
end;
type
TSystem_Performance_Information = packed record
liIdleTime: LARGE_INTEGER; {LARGE_INTEGER}
dwSpare: array[075] of DWORD;
end;
type
TSystem_Time_Information = packed record
liKeBootTime: LARGE_INTEGER;
liKeSystemTime: LARGE_INTEGER;
liExpTimeZoneBias: LARGE_INTEGER;
uCurrentTimeZoneId: ULONG;
dwReserved: DWORD;
end;
var
NtQuerySystemInformation: function(infoClass: DWORD;
buffer: Pointer;
bufSize: DWORD;
returnSize: TPDword): DWORD; stdcall = nil;
liOldIdleTime: LARGE_INTEGER = ();
liOldSystemTime: LARGE_INTEGER = ();
SysBaseInfo: TSystem_Basic_Information;
SysPerfInfo: TSystem_Performance_Information;
SysTimeInfo: TSystem_Time_Information;
status: Longint; {long}
dbSystemTime: Double;
dbIdleTime: Double;
function GetCPUUsage:Double;
implementation
function Li2Double(x: LARGE_INTEGER): Double;
begin
Result := xHighPart 4294967296E9 + xLowPart
end;
function GetCPUUsage:Double;
var
bLoopAborted : boolean;
begin
if @NtQuerySystemInformation = nil then
NtQuerySystemInformation := GetProcAddress(GetModuleHandle(‘ntdlldll‘),
‘NtQuerySystemInformation‘);
// get number of processors in the system
status := NtQuerySystemInformation(SystemBasicInformation, @SysBaseInfo, SizeOf(SysBaseInfo), nil);
if status <> 0 then Exit;
// Show some information
{with SysBaseInfo do
begin
ShowMessage(
Format(‘uKeMaximumIncrement: %d‘#13‘uPageSize: %d‘#13+
‘uMmNumberOfPhysicalPages: %d‘+#13+‘uMmLowestPhysicalPage: %d‘+#13+
‘uMmHighestPhysicalPage: %d‘+#13+‘uAllocationGranularity: %d‘#13+
‘uKeActiveProcessors: %d‘#13‘bKeNumberProcessors: %d‘,
[uKeMaximumIncrement, uPageSize, uMmNumberOfPhysicalPages,
uMmLowestPhysicalPage, uMmHighestPhysicalPage, uAllocationGranularity,
uKeActiveProcessors, bKeNumberProcessors]));
end;
}
bLoopAborted := False;
while not bLoopAborted do
begin
// get new system time
status := NtQuerySystemInformation(SystemTimeInformation, @SysTimeInfo, SizeOf(SysTimeInfo), 0);
if status <> 0 then Exit;
// get new CPU‘s idle time
status := NtQuerySystemInformation(SystemPerformanceInformation, @SysPerfInfo, SizeOf(SysPerfInfo), nil);
if status <> 0 then Exit;
// if it‘s a first call - skip it
if (liOldIdleTimeQuadPart <> 0) then
begin
// CurrentValue = NewValue - OldValue
dbIdleTime := Li2Double(SysPerfInfoliIdleTime) - Li2Double(liOldIdleTime);
dbSystemTime := Li2Double(SysTimeInfoliKeSystemTime) - Li2Double(liOldSystemTime);
// CurrentCpuIdle = IdleTime / SystemTime
dbIdleTime := dbIdleTime / dbSystemTime;
// CurrentCpuUsage% = 100 - (CurrentCpuIdle 100) / NumberOfProcessors
dbIdleTime := 1000 - dbIdleTime 1000 / SysBaseInfobKeNumberProcessors + 05;
// Show Percentage
//Form1Label1Caption := FormatFloat(‘CPU Usage: 00 %‘,dbIdleTime);
//ApplicationProcessMessages;
// Abort if user pressed ESC or Application is terminated
Result:=dbIdleTime;
bLoopAborted:=True;
//bLoopAborted := (GetKeyState(VK_ESCAPE) and 128 = 128) or ApplicationTerminated;
end;
// store new CPU‘s idle and
var
i :Integer;
begin
for i := 0 to ComponentCount - 1 do
if Components[i] is TRadioButton then
if (Components[i] as TRadioButton)Checked then
begin
ShowMessage((Components[i] as TRadioButton)Caption);
Break;
end;
end;
用 delphi 获取网关信息,有多种方法,以下提供从注册表中读取的方法:
procedure TForm1Button1Click(Sender: TObject);function MultSz2String(aBuffer: array of char):string;
var
temp: string;
BufferIndex:Integer;
LastTimeIsZero: Boolean;
begin
LastTimeIsZero := False;
for BufferIndex := 0 to Sizeof(aBuffer) do
begin
temp := string(aBuffer[BufferIndex]);
if temp = #0 then
begin
if LastTimeIsZero then Break; //连续两前#0,就是结束了。
LastTimeIsZero := True;
end
else
LastTimeIsZero := False;
Result := Result + temp;
end;
end;
var
i: integer;
reg: TRegistry;
lst: TStringList;
sKey,s: string;
Buffer: array[01024] of char;
begin
lst := TStringListCreate;
reg := TRegistryCreate;
regRootKey := HKEY_LOCAL_MACHINE;
if regOpenKeyReadOnly('SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards') then
begin
regGetKeyNames(lst);
regCloseKey;
for i := 0 to lstCount-1 do
begin
Memo1LinesAdd('网卡'+iToString()+':');
sKey := 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\'+lst[i];
if regOpenKeyReadOnly(sKey) then
begin
Memo1LinesAdd('Description:'+regReadString('Description'));
s := regReadString('ServiceName');
Memo1LinesAdd('ServiceName:'+s);
end;
regCloseKey;
sKey := 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\'+s;
regOpenKeyReadOnly(sKey);
if regReadBool('EnableDHCP') then
begin
Memo1LinesAdd('DhcpIPAddress:'+regReadString('DhcpIPAddress'));
regReadBinaryData('DhcpDefaultGateway', Buffer, Sizeof(Buffer));
Memo1LinesAdd('DhcpDefaultGateway:'+MultSz2String(Buffer));
end else
begin
Memo1LinesAdd('IPAddress:'+regReadString('IPAddress'));
Memo1LinesAdd('DefaultGateway:'+regReadString('DefaultGateway'));
end;
regCloseKey;
Memo1LinesAdd('');
end;
end;
regFree;
lstFree;
end;
代码运行截图:
以上就是关于delphi怎么获取字符串之间多个字符内容全部的内容,包括:delphi怎么获取字符串之间多个字符内容、DELPHI如何获取一台机器的CPU占用率、delphi 获取动态创建控件内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)