program StringLengthWithoutSpaces;
var
myString: string;
lengthWithoutSpaces, i: Integer;
begin
myString := 'a ab abc abcd';
// Initialize the counter for length excluding spaces
lengthWithoutSpaces := 0;
// Iterate through the string and count non-space characters
for i := 1 to Length(myString) do
begin
if myString[i] <> ' ' then
Inc(lengthWithoutSpaces); // Increment the counter if the character is not a space
end;
WriteLn('The length of the string "', myString, '" excluding spaces is: ', lengthWithoutSpaces);
end.
(*
run:
The length of the string "a ab abc abcd" excluding spaces is: 10
*)