Reputation: 13
How can I set the specified character by index to empty character in Delphi6?
procedure TMainForm.Button1Click(Sender: TObject);
var i: integer;
s_ord_account : String[10];
begin
s_ord_account := '0930002930' ;
i := 1;
REPEAT
IF s_ord_account[i] = '0' THEN
s_ord_account[i] := '';
INC(i);
UNTIL (i=5) OR (s_ord_account[i] <> ' ');
MessageDlg(s_ord_account,mtError, mbOKCancel, 0);
yend;
When I try to execute this code I get an error
[Error] Main.pas(30): Incompatible types: 'Char' and 'String'
Upvotes: 1
Views: 217
Reputation: 612954
First of all it would make a lot of sense for you to stop using Turbo Pascal strings and use the native Delphi string type, string
.
There is no such thing as an empty character. You can use the Delete
function to remove a character from the string. A simpler approach would be to use the StringReplace
function. That renders your code entirely needless.
{$APPTYPE CONSOLE}
uses
SysUtils;
var
s: string;
begin
s := StringReplace('0930002930', '0', '', [rfReplaceAll]);
Writeln(s);
end.
Output
93293
Upvotes: 1