Solved

Read string into Array of Char?

Posted on 1998-05-20
4
305 Views
Last Modified: 2010-08-05
How would I go about reading a string variable into a Character array.  e.g.

Message : array[1..30] of char;

I would like to read in the string variable from a TFileListBox.

Thanks.
0
Comment
Question by:sparklin
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
kjteng earned 30 total points
ID: 1346900
TRY THIS:

procedure StringToArray(var  arr: array of char; inStr: string);
var i, last:integer;
begin
  last:= length( inStr);
  for i:=0 to high(arr) do
    if i<last then
      arr[i]:= inStr[i+1]
    else
      arr[i]:=' ';
end;

0
 

Author Comment

by:sparklin
ID: 1346901
This procedure does not seem to work in Delphi 3 as the string and char variables in the line: arr[i]:= inStr[i+1]   are not compatible.
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1346902
I compiled the code in both on D1 and D3. Seems no problem.
Why are arr[i] and instr[i+1] not compatible? i thought they are both char type.
Did you use any compiler directive in your program? I am using default setting ie. {$H+}
0
 

Author Comment

by:sparklin
ID: 1346903
My misttake..Sorry.  YOUR code is fine but I still had the array[1.14] OFCHAR variable defined.  Array of char works fine.

Thanks again.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question