954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

convert string to array

I've stored an array in an html hidden input and now need to transfer that array to my delphi function. I've tried:

var
  fileArray : array of string;

fileArray := formvar('fileArray', '');

but this gives an incompatible types error when I compile. How can I convert the string into an array so that it can be stored in the variable? Also, if it helps, the formvar fileArray is comma delimited.

yssirhc
Light Poster
26 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

IS "formvar" part of Delphi or your own method? I could not find a reference for it and am not familiar with it. Either way, what is the declaration for the function? Have you looked at tstringlist?

Also check out extractstrings in the Classes unit.

jsosnowski
Junior Poster in Training
68 posts since Nov 2007
Reputation Points: 11
Solved Threads: 11
 

Put that string in a variable.

var a:String;

{in pascal,strings can be handle as array}
{example} 
a:= 'Hello';

a[0]:= 5;   {this is a number of chars,here:5}
a[1]:='H';
a[2]:='e';
a[3]:='l';
a[4]:='l';
a[5]:='o';
FlamingClaw
Posting Pro
559 posts since Feb 2009
Reputation Points: 132
Solved Threads: 138
 

or see my another example:

Program StringIntoArray;

Uses Crt;
Const max = 11;
Var S:String[max];
    i:Byte;
    size:Byte;
    Ar:Array[1..max]of Char;


Begin {main}
     ClrScr;
     Write('Give me the word,max 11 char: ');
     ReadLn(S);
     size:=Length(S);
     For i:=1 To size Do
        Begin
           Ar[i]:=S[i];
           If (i = size) Then Break;
        End;

     {Now write the results}
     For i:=1 To size Do WriteLn(Ar[i]);

     ReadKey;
End. {main}
(*Created By FlamingClaw 2009.03.11*)
FlamingClaw
Posting Pro
559 posts since Feb 2009
Reputation Points: 132
Solved Threads: 138
 

FlamingClaw,

You could also use "absolute" to align the two variables in memory by declaring:

Var
  S : string;
  B : Array of Byte Absolute S;

This allows you to read and write to the string or array using the same memory area. It is similar to Union in C++.

But I do not think this is what yssirhc is after.

jsosnowski
Junior Poster in Training
68 posts since Nov 2007
Reputation Points: 11
Solved Threads: 11
 

'jsosnowski'

I think you did not understand me.I'm not speaking of number of bytes of a string...
If you have a string then you can put it into an array if you divide that string for characters...In my above example,that's a pascal example,can be look that....
But if we speaking about delphi then see the down link for more information...
http://delphi.about.com/cs/adptips2002/a/bltip1102_5.htm

FlamingClaw
Posting Pro
559 posts since Feb 2009
Reputation Points: 132
Solved Threads: 138
 

I thought formVar was part of Delphi, but as you can probably tell I'm not all that familiar with this language & didn't write that part of the code.

Using a TStringList worked well though.

fileList := TStringList.Create;
fileList.CommaText := formvar('fileArray', '');
for count := 0 to fileList.Count-1 do


Thanks for the suggestions! :)

yssirhc
Light Poster
26 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You