eturns a string with occurrences of one substring replaced by another substring.UnitSysUtilsCategorystring handling routinestype TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase); function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;DescriptionStringReplace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern. StringReplace assumes that the source string, specified by S, may contain Multibyte characters.If the Flags parameter does not include rfReplaceAll, StringReplace only replaces the first occurrence of OldPattern in S. Otherwise, all instances of OldPattern are replaced by NewPattern.If the Flags parameter includes rfIgnoreCase, The comparison operation is case insensitive.
s := ,12,32,43,543, Trim(StringReplace(s, ',', ' ', [rfReplaceAll])) 就是你想要的结果下面是分成数据组 function ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings): Integer;例: procedure TForm1.Button1Click(Sender: TObject); var s:String; begin s:='11.22.33.44'; ExtractStrings(['.'],[' '],pchar(s),memo1.Lines); end;
用这个函数:(头尾没有分隔符) function Split(const S: string; const Delimiter: string = ' '): TStrings; var I: Integer; strTemp: string; begin Result := TStringList.Create; if (Delimiter = '') or (S = '') then Exit; strTemp := S; repeat I := Pos(Delimiter, strTemp); if I > 0 then begin Result.Add(Copy(strTemp, 1, I - 1)); Delete(strTemp, 1, (I + Length(Delimiter) - 1)); end else Result.Add(strTemp); until I <= 0; end;调用: var slTemp: TStrings; begin slTemp := TstringList.create; slTemp := Split(DBMemo2.Text, ';'); ... slTemp.free; end;
TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;DescriptionStringReplace replaces occurrences of the substring specified by OldPattern with the substring specified by NewPattern. StringReplace assumes that the source string, specified by S, may contain Multibyte characters.If the Flags parameter does not include rfReplaceAll, StringReplace only replaces the first occurrence of OldPattern in S. Otherwise, all instances of OldPattern are replaced by NewPattern.If the Flags parameter includes rfIgnoreCase, The comparison operation is case insensitive.
Trim(StringReplace(s, ',', ' ', [rfReplaceAll]))
就是你想要的结果下面是分成数据组
function ExtractStrings(Separators, WhiteSpace: TSysCharSet; Content: PChar; Strings: TStrings): Integer;例:
procedure TForm1.Button1Click(Sender: TObject);
var
s:String;
begin
s:='11.22.33.44';
ExtractStrings(['.'],[' '],pchar(s),memo1.Lines);
end;
function Split(const S: string; const Delimiter: string = ' '): TStrings;
var
I: Integer;
strTemp: string;
begin
Result := TStringList.Create;
if (Delimiter = '') or (S = '') then Exit;
strTemp := S;
repeat
I := Pos(Delimiter, strTemp);
if I > 0 then
begin
Result.Add(Copy(strTemp, 1, I - 1));
Delete(strTemp, 1, (I + Length(Delimiter) - 1));
end
else
Result.Add(strTemp);
until I <= 0;
end;调用:
var
slTemp: TStrings;
begin
slTemp := TstringList.create;
slTemp := Split(DBMemo2.Text, ';');
...
slTemp.free;
end;