Länge eines Strings

#1702629
Lesenswert?

Guten Tag

In eine anderen Forum bin ich auf folgenden Eintrag gestossen:

Make 'toto' a variable of type LINE, from package STD.TEXTIO.
Then you can copy any string into it using the WRITE procedure:

variable toto: LINE; -- initialised to empty!
...
if A=0 then
WRITE(toto, t1);
else
WRITE(toto, t2);
end if;

Don't forget that the WRITE procedure adds things to the end
of the string stored in 'toto', so that it grows ever longer.
To reset it back to "empty", simply:

DEALLOCATE(toto);

Which leads us to an attractive procedure that has the effect
of copying any string into a LINE variable, having first
cleared that variable:

procedure put(L: inout LINE; S: in STRING) is
begin
DEALLOCATE(L);
WRITE(L, S);
end;

Now, of course, you have the problem of how to make use of
the string contents of the line variable. Given a variable
L of type LINE, you can...
* get hold of the whole string contents:
report "Message is " & L.ALL;
* take a slice of it, just like a string:
variable c: CHARACTER;
...
c := L(1);
* find its length:
if L'LENGTH > 50 then ...

Allerdings funktioniert bei mir das Attribut 'LENGTH sowie die Procedur 
DEALLOCATE nicht! Die STD-Library habe ich eingebunden und auch das File 
STD.TEXTIO.ALL.
Hat jemand eine andere Lösung, die Anzahl Zeichen in einer Line zu 
ermitteln, sowie die Line zu löschen?

Gruss
Thomas

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren