convert string to array

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2009
Posts: 24
Reputation: yssirhc is an unknown quantity at this point 
Solved Threads: 0
yssirhc yssirhc is offline Offline
Newbie Poster

convert string to array

 
0
  #1
Mar 11th, 2009
I've stored an array in an html hidden input and now need to transfer that array to my delphi function. I've tried:
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 68
Reputation: jsosnowski is an unknown quantity at this point 
Solved Threads: 11
jsosnowski's Avatar
jsosnowski jsosnowski is offline Offline
Junior Poster in Training

Re: convert string to array

 
0
  #2
Mar 11th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 447
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: convert string to array

 
0
  #3
Mar 11th, 2009
Put that string in a variable.
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 447
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: convert string to array

 
0
  #4
Mar 11th, 2009
or see my another example:
  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*)
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 68
Reputation: jsosnowski is an unknown quantity at this point 
Solved Threads: 11
jsosnowski's Avatar
jsosnowski jsosnowski is offline Offline
Junior Poster in Training

Re: convert string to array

 
0
  #5
Mar 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 447
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: convert string to array

 
0
  #6
Mar 13th, 2009
'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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 24
Reputation: yssirhc is an unknown quantity at this point 
Solved Threads: 0
yssirhc yssirhc is offline Offline
Newbie Poster

Re: convert string to array

 
0
  #7
Mar 18th, 2009
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.
  1. fileList := TStringList.Create;
  2. fileList.CommaText := formvar('fileArray', '');
  3. for count := 0 to fileList.Count-1 do

Thanks for the suggestions!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC