Logo

Programming-Idioms

History of Idiom 53 > diff from v29 to v30

Edit summary for version 30 by :
New Ada implementation by user [Smaehtin]

Version 29

2016-02-16, 18:00:02

Version 30

2016-02-16, 18:59:57

Idiom #53 Join a list of strings

Concatenate elements of string list x joined by the separator ", " to create a single string y.

Idiom #53 Join a list of strings

Concatenate elements of string list x joined by the separator ", " to create a single string y.

Imports
with Ada.Containers.Indefinite_Vectors; use Ada.Containers;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
Code
declare
   Last : Cursor := X.Last;
   Y : Unbounded_String;
         
begin
   for C in X.Iterate loop
      Y := Y & Element (C) & (if C = Last then "" else ", ");
   end loop;
end;