Link to home
Start Free TrialLog in
Avatar of msmouse
msmouse

asked on

Converting a string to an Array

I'm Pulling information from a DataBase in the form of a string.  I need to know how to convert the data into an array.

D := Table1.FieldByName ('drives').AsString;

I have an array defined
MyArray : array[0..15] of char;
when I try to assign D to MyArray I keep getting incompatible types
'Array' 'String'  
MyArray := D;

I need to look at the data from the database one Character at a time.
ASKER CERTIFIED SOLUTION
Avatar of Lischke
Lischke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lischke
Lischke

Sorry, only the second solution works. Casting the array to anything does only produce the well known "left side cannot be assigned to" error.

Ciao, Mike
Hello,

First, why don't you use a dynamic array. With the array you use, you are always fixed to a specific size. So try
 
  var
    MyArray : array of Char;

instead of your first thing. Then set the length of the array with SetLength(MyArray, e.g. 15). That's the first thing. You can access the array as usual.

After that you can get the value of your database with

var
  D : string;

begin  
  D := Table1.FieldByName      ('drives').AsString;

  if (D <> '') then
  begin
    MyArray[0] := D[1]; // First element in string
  end
  else MyArray := #0;
end;
   
Hi msedi,

welcome on E-E :-) I want to let you know that proposing an answer is considered bad behaviour and against the rules here if someone else (in this case me :-)) has already commented to the question. Of course, if you are very sure you have the solution and all other just have given nonsense then proposing an answer is acceptable. But this usually happens very seldom and when using only comments then the questioneer can pick one and promote it to being an answer. Additionally, it happend quite often (also to me) that the proposed answer has been accepted accidently although another one was meant, because the questioneer thought the answer came from the same person as the previous comments.

Thank you and

Ciao, Mike
Sorry,

I didn't see that.

Greetings, Martin
Avatar of msmouse

ASKER

msedi,  I tried your way but you get 'dynamic Array' 'char' error.

Lischke  The move function seems to be a step in the right direction, I'm not getting the types error.

Avatar of msmouse

ASKER

A step in the right direction, Now I just have to work with getting the array to do what I want.

Thanks