Länge eines Strings

OP #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

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.