ArrayToString( )

Purpose
Converts a string array list to a delimited string.
 
Author Date of code (original) Updated on Date of page (original) Updated on
Bill Thoen
bthoen@ctmap.com
07Jan2001
07Jan2001
07Jan2001
09Jan2001
 
Restrictions on use
This module is distributed under the terms of the Lesser GNU General Public License. Restrictions on the use of this work in a commercial application or derivative work is described in the Lesser GNU General Public License page at: http://www.fsf.org/copyleft/lesser.html
 
Description
ArrayToString converts an array of strings into a single delimited string. This is most commonly used to create MapInfo semi-colon delimited strings for use in dialogs (e.g. "One;Two;Three", but can also be used to combine strings with a more complex delimiter such as <BR>.
 
External resources
none
 
Declare statement of sub_function. Include in your program. Copy/Paste if needed.
sub ArrayToString (
   sList() as string,      'List items as string array
   sStr as string,         'Returned list items as delimited string
   byval sToken as string) 'Delimiter separating items in sStr

 
Returned value(s) (function only)

 
Other required declare statement(s). Include in your program. Copy/Paste if needed.
include "StringLists.def"
 
MapBasic Code. Copy/Paste if needed.
sub ArrayToString (
   sList() as string,
   sStr as string,
   byval sToken as string)

dim i as smallint

   sStr = sList(1)
   for i = 2 to UBound(sList)
      sStr = sStr + sToken + sList(i)
   next

end sub
 
Availability for download
StringLists.zip
 
Example
include "StringLists.def"

dim sList(3), sListMI as string

   sList(1) = "Red"
   sList(2) = "Green"
   sList(3) = "Blue"

   call ArrayToString (sList, sListMI, ";")

   'sListMI now contains "Red;Green;Blue"
 
Comments

 
See also
StringToArray( )