Solved

Read string into Array of Char?

Posted on 1998-05-20
4
325 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month3 days, 23 hours left to enroll

630 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