تقسيم النص
#9
تحديث للدالة لتفادي Memory Leaks :
PHP كود :
// By SMP3
function SplitStr(const AStr: String; n: integer): string;
var
  
s, PropStr: PChar;
  
Len, MemLen, i, D: integer;
  
c: char;
  
MemTxt, FTxt, TmpStr: string;
begin
  D 
:= 0;
  
MemTxt := AStr;
  
Len := Length(MemTxt);
  if 
Len < n then
    Result 
:= AStr;

  
GetMem(PropStr, Len {$IFDEF UNICODE} * 2{$ENDIF});
  
MemLen := Len {$IFDEF UNICODE} * 2{$ENDIF};
  
s := PChar(MemTxt);
  for 
i := 0 to Len {$IFDEF UNICODE} * 2{$ENDIF} do
    
begin
      
if s^ <> #$D then
        
begin
          inc
(s);
          if 
s^ <> #$A then
            
begin
              dec
(s);
              
PropStr^ := s^;
              
inc(s);
              
inc(D);
              
inc(PropStr);
            
end
          
else
            
begin
              inc
(D);
              
inc(s, 2);
              
PropStr^ := ' ';
              
inc(PropStr);
            
end;
        
end
      
else
        
begin
          inc
(D);
          
inc(s, 2);
          
PropStr^ := ' ';
          
inc(PropStr);
        
end;
    
end;

  
dec(PropStr, D);
  
MemTxt := PropStr;
  
Len := 0;
  
FTxt := '';
  
TmpStr := '';

  while 
0 <= Length(MemTxt) - Len do
    
begin
      TmpStr 
:= Copy(PropStr, 0, n);

      
FTxt := FTxt + TmpStr + #13#10;
      
inc(PropStr, n);
      
inc(Len, n);
      if 
PropStr^ = ' ' then
        begin
          inc
(PropStr, +1);
          
inc(Len, +1);
        
end;
    
end;
  
dec(PropStr, Len);
  
Len := Length(FTxt);
  
FTxt[Len - 1] := #0;
  
FTxt[Len - 2] := #0;

  
Result := FTxt;
  
FreeMem(PropStr, MemLen{$IFDEF UNICODE} * 2{$ENDIF});

end; 
Open Your Source .. Open Your Mind
الرد


الردود في هذا الموضوع
تقسيم النص - بواسطة maryos - 23-08-2013, 06:45 PM
تقسيم النص - بواسطة Agmcz - 24-08-2013, 01:10 AM
تقسيم النص - بواسطة maryos - 24-08-2013, 02:04 AM
تقسيم النص - بواسطة SMP3 - 24-08-2013, 03:25 AM
تقسيم النص - بواسطة maryos - 24-08-2013, 04:33 AM
تقسيم النص - بواسطة S.FATEH - 24-08-2013, 11:06 AM
تقسيم النص - بواسطة SMP3 - 24-08-2013, 04:53 PM
تقسيم النص - بواسطة SMP3 - 24-08-2013, 05:10 PM
تقسيم النص - بواسطة SMP3 - 24-08-2013, 05:16 PM
تقسيم النص - بواسطة maryos - 24-08-2013, 06:11 PM
تقسيم النص - بواسطة Agmcz - 24-08-2013, 10:23 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم