Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2010.08.27;
Скачать: CL | DM;

Вниз

Выдернуть из переменной TStringList нужну строку   Найти похожие ветки 

 
tonick2001 ©   (2010-02-21 10:56) [0]

Есть переменная типа TStringList которая содержит вот такую инфу:
instance of Win32_Processor
{
AddressWidth = 64;
Architecture = 9;
Availability = 3;
Caption = "Intel64 Family 15 Model 6 Stepping 2";
CpuStatus = 1;
CreationClassName = "Win32_Processor";
CurrentClockSpeed = 3010;
CurrentVoltage = 13;
DataWidth = 64;
Description = "Intel64 Family 15 Model 6 Stepping 2";
DeviceID = "CPU0";
ExtClock = 200;
Family = 178;
L2CacheSize = 4096;
L2CacheSpeed = 3010;
L3CacheSize = 0;
L3CacheSpeed = 0;
Level = 15;
LoadPercentage = 99;
Manufacturer = "GenuineIntel";
MaxClockSpeed = 3010;
Name = "Intel(R) Pentium(R) D CPU 3.00GHz";
NumberOfCores = 2;
NumberOfLogicalProcessors = 2;
PowerManagementSupported = FALSE;
ProcessorId = "BFEBFBFF00000F62";
ProcessorType = 3;
Revision = 1538;
Role = "CPU";
SocketDesignation = "Socket 775";
Status = "OK";
StatusInfo = 3;
Stepping = "2";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "COMP01";
UpgradeMethod = 1;
Version = "Model 6, Stepping 2";
};

Необходимо выдернуть строку с полем name.

Функция натыкается на первую попавшую строку которая содержит name то есть CreationClassName, как сделать так что бы она смотрела только на начало строки, т.е на ту строку которая начинается с Name и до этого ничего нет.


function _ExtractValue(Data:string):string;
 var
   str:string;
   index, i:integer;
   TS:TStrings;
 begin
   Result := "";
   TS := TStringList.Create();
   try
     TS.Text := StrInfo;

      for i := 0 to (TS.Count - 1) do begin
        Str := Trim(TS[i]);
       index := AnsiPos(Data + " = ", Str);
       if (index <> 0) then begin

         Str := Copy(Str, index + Length(Data + " = "), Length(Str));
         Str := Trim(Str);


         if Str[1]= """ then begin
           Str := Copy(Str, 2, Length(Str));
         end;

         Str := AnsiReplaceText(Str, "";", "");


         if (Length(Str) > 1) then begin

           if Str[Length(Str)]= ";" then begin
             Str := Copy(Str, 1, Length(Str) - 1);
           end;
         end;

         Result := Str;
         Break;
       end;
     end;


 
Вася   (2010-02-21 11:15) [1]

Попробуй так
Result := StringList.Values["Name "]


 
Юрий Зотов ©   (2010-02-21 11:20) [2]

Способ 1 - см. свойство Values.
Способ 2 - if Pos("Name", Str) = 1 then


 
Tonick2001 ©   (2010-02-21 14:39) [3]

Спасибо, сделал.

Function Get_Lines (strng:string):string;
 var i,j:integer;
     str:string;
     counts:integer;
     StartCh:integer;
     List:TStringList;
 begin
 List := TStringList.Create;
 List.Text:=strng;
  For i:=0 to (List.Count-1) do
   Begin
    str:=Trim(List[i]);
    if Pos("Name",str)=1 then
     begin
      For j:=1 to Length(str) do
       begin
        counts:=j;
        if str[j]="=" then
         begin
          Delete(str,1,counts);
          str:=Trim(str);
          break;
         end;
       end;
    For j:=1 to length(str) do
     begin
      startCH:=j;
      if (str[j]=""") then
       begin
        Delete(str,StartCh,1);
        str:=Trim(str);
       end;
     end;
    For j:=1 to length(str) do
     begin
      startCH:=j;
      if (str[j]=";") then
       begin
        Delete(str,StartCh,1);
        str:=Trim(str);
        Break;
       end;
     end;
     Result:=str;
     Break;
   end;
 end;
 end;



Страницы: 1 вся ветка

Текущий архив: 2010.08.27;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.119 c
15-1272288456
JollyRoger128bit87
2010-04-26 17:27
2010.08.27
задний фон в эксплорери


11-1219867277
Лотос
2008-08-28 00:01
2010.08.27
Аттрибуты для NewDirList


15-1275083308
Германн
2010-05-29 01:48
2010.08.27
Сдвинуть блок текста в IDE влево


3-1239785375
ocean
2009-04-15 12:49
2010.08.27
Как лучше искать по текстовому полю?


2-1273649711
@!!ex
2010-05-12 11:35
2010.08.27
Обработка сообщений в отдельном потоке.