Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

comma delimited string into array

1,052 views
Skip to first unread message

Jeff

unread,
Sep 8, 2006, 7:00:23 AM9/8/06
to
Is there a function to input values separated by commas in a string into an
array?

ie:
string = 'one,two,three'

MyArray[1] = 'one'
MyArray[2] = 'two'
MyArray[3] = 'three'

I know i can use a loop and the pos function, but is there a shorter method?


Jay Williams

unread,
Sep 8, 2006, 8:08:35 AM9/8/06
to
You could probably create a DataStore, do an ImportString and then loop over
the rows and insert them into the array.

Some languages such as PHP support this natively, but PowerBuilder does not.

"Jeff" <nob...@nowhere.com> wrote in message news:45014d47$1@forums-1-dub...

Fred

unread,
Sep 8, 2006, 8:10:00 AM9/8/06
to
instancename.of_ParseToArray ( source, delimiter, array )

Argument Description
instancename Instance name of n_cst_string
source String to be converted into an array
delimiter String specifying the character(s) that
separate array elements in source
array String array into which the function
places the extracted strings (passed by reference)

/ Separate the statement into multiple statements,
// Separated by UNIONs

li_numstats = lnv_string.of_Parsetoarray (as_sql, "UNION", ls_sql)


Roland Smith

unread,
Sep 8, 2006, 8:15:04 AM9/8/06
to
That would depend on what version of PB you are using.

If you are using PB9 or higher you can use ImportString to put it into a
datastore and then extract it into an array like this:

DataStore lds_import
String ls_empname[]

lds_import = Create DataStore
lds_import.DataObject = "d_myimportdw"

ls_empname = lds_import.Object.empname.Primary


The datawindow object d_myimportdw would be an external with a single column
called empname and a length large enough to hold the largest possible value.

PB8 and earlier only support tab-delimited for the ImportString function so
you would have to use the Pos loop method.

Roland


"Jeff" <nob...@nowhere.com> wrote in message news:45014d47$1@forums-1-dub...

Boris Gasin [TeamSybase]

unread,
Sep 8, 2006, 9:15:30 AM9/8/06
to

There is no native PowerScript function to do this.

You will need to roll your own or use this one
http://www.pbdr.com/pbtips/ps/quks2ary.htm

Terry Voth

unread,
Sep 8, 2006, 9:18:42 AM9/8/06
to
This would be assuming you're using PFC. If you're not, you can find the code
for this function here: http://tinyurl.com/mkpl3.

Good luck,

Terry [TeamSybase] and Sequel the techno-kitten

On 8 Sep 2006 05:10:00 -0700,
in sybase.public.powerbuilder.general

*********************************
PowerBuilder for $95? No.
Personal use PowerBuilder Enterprise *AND* PocketBuilder *AND* DataWindow.NET
*AND* Sybase IQ as free benefits of am ISUG membership. See
http://www.isug.com/ISUG3/Membership_benefits.html for details.

*********************************
Click once a day to help the hungry
http://www.thehungersite.com
*********************************
User Manual
===========
TeamSybase <> Sybase employee
Forums = Peer-to-peer
Forums <> Communication with Sybase
IsNull (AnswerTo (Posting)) can return TRUE
Forums.Moderated = TRUE, so behave or be deleted
*********************************

Sequel's Sandbox: http://www.techno-kitten.com
Home of PBL Peeper, a free PowerBuilder Developer's Toolkit.
Version 3.0.02 now available at the Sandbox
PB Futures updated Apr 24/2006
See the PB Troubleshooting & Migration Guides at the Sandbox
^ ^
o o
=*=

miguelJose

unread,
Sep 11, 2006, 6:04:53 AM9/11/06
to
I think this is what you might be looking for?
string ls[]
ls = {'abc','def','ghi'}
0 new messages