Solved

Read string into Array of Char?

Posted on 1998-05-20
4
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Magic Software info 18 154
LAN or WAN ? 11 120
Base1 Encode/Decode 3 100
File Downloader in Multi threading , Measure Download Speed and progress 9 45
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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