943,718 Members | Top Members by Rank

Ad:
Mar 11th, 2009
0

convert string to array

Expand Post »
I've stored an array in an html hidden input and now need to transfer that array to my delphi function. I've tried:
delphi Syntax (Toggle Plain Text)
  1. var
  2. fileArray : array of string;
  3.  
  4. 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
yssirhc is offline Offline
26 posts
since Feb 2009
Mar 11th, 2009
0

Re: convert string to array

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.
Reputation Points: 11
Solved Threads: 11
Junior Poster in Training
jsosnowski is offline Offline
68 posts
since Nov 2007
Mar 11th, 2009
0

Re: convert string to array

Put that string in a variable.
pascal Syntax (Toggle Plain Text)
  1. var a:String;
  2.  
  3. {in pascal,strings can be handle as array}
  4. {example}
  5. a:= 'Hello';
  6.  
  7. a[0]:= 5; {this is a number of chars,here:5}
  8. a[1]:='H';
  9. a[2]:='e';
  10. a[3]:='l';
  11. a[4]:='l';
  12. a[5]:='o';
Last edited by FlamingClaw; Mar 11th, 2009 at 5:35 pm.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Mar 11th, 2009
0

Re: convert string to array

or see my another example:
pascal Syntax (Toggle Plain Text)
  1.  
  2. Program StringIntoArray;
  3.  
  4. Uses Crt;
  5. Const max = 11;
  6. Var S:String[max];
  7. i:Byte;
  8. size:Byte;
  9. Ar:Array[1..max]of Char;
  10.  
  11.  
  12. Begin {main}
  13. ClrScr;
  14. Write('Give me the word,max 11 char: ');
  15. ReadLn(S);
  16. size:=Length(S);
  17. For i:=1 To size Do
  18. Begin
  19. Ar[i]:=S[i];
  20. If (i = size) Then Break;
  21. End;
  22.  
  23. {Now write the results}
  24. For i:=1 To size Do WriteLn(Ar[i]);
  25.  
  26. ReadKey;
  27. End. {main}
  28. (*Created By FlamingClaw 2009.03.11*)
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Mar 12th, 2009
0

Re: convert string to array

FlamingClaw,

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

Pascal and Delphi Syntax (Toggle Plain Text)
  1. Var
  2. S : string;
  3. 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.
Reputation Points: 11
Solved Threads: 11
Junior Poster in Training
jsosnowski is offline Offline
68 posts
since Nov 2007
Mar 13th, 2009
0

Re: convert string to array

'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/adptips20...ltip1102_5.htm
Last edited by FlamingClaw; Mar 13th, 2009 at 8:30 am.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Mar 18th, 2009
0

Re: convert string to array

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.
delphi Syntax (Toggle Plain Text)
  1. fileList := TStringList.Create;
  2. fileList.CommaText := formvar('fileArray', '');
  3. for count := 0 to fileList.Count-1 do

Thanks for the suggestions!
Reputation Points: 10
Solved Threads: 0
Light Poster
yssirhc is offline Offline
26 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Conditional statements in Pascal
Next Thread in Pascal and Delphi Forum Timeline: App's with lots of strings. How?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC