![]() |
AW: Strings zusammenführen und Bereinigen
Eine Lösung die die Reihenfolge der Elemente nicht tauscht und auch mit einzelnen Wörtern klar kommt:
Delphi-Quellcode:
function ContainsElement(const AContainer, AElement: string): Boolean;
begin for var lItem in AContainer.Split([',']) do begin if lItem = AElement then Exit(True); end; Result := False; end; procedure AddElement(var AContainer: string; const AElement: string); begin if not ContainsElement(AContainer, AElement) then AContainer := AContainer + ',' + AElement; end; procedure AddElementList(var AContainer: string; const AList: string); begin for var lItem in AList.Split([',']) do AddElement(AContainer, lItem); end; var s1 := '1,2,4'; const s2 = 'Test,3,2,4,5'; AddElementList(s1, s2); Assert(s1 = '1,2,4,Test,3,5'); |
AW: Strings zusammenführen und Bereinigen
Delphi-Quellcode:
bzw.
ContainsElement(Container, Element)
ContainsStr(',' + Element + ',', ',' + Container + ',') MatchStr(Element, Container.Split([','])) ...
Delphi-Quellcode:
// Contains
if MatchStr(Element, ContainerArray) then // Add if not MatchStr(Element, ContainerArray) then ContainerArray := ContainerArray + [Element]; // oder Insert() // Remove var i := IndexStr(Element, ContainerArray); if i >= 0 then Delete(ContainerArray, i); // AsString S := string.Join(',', ContainerArray); |
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:22 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz