t44_strindex.pas 749 B

123456789101112131415161718192021222324252627282930
  1. program t44;
  2. (* String subscripts, s[i], in both directions.
  3. A STRING is a length byte at s[0] followed by the characters, so s[i]
  4. selects the single byte at off+i: reading it yields a CHAR, and assigning to
  5. it stores one byte. Both a global and a local string are exercised, because
  6. the address paths differ (absolute vs [BP+off]). Only a CONSTANT index is
  7. covered: a variable index is ENoLib here, exactly as it already is for an
  8. array. *)
  9. var
  10. g : string[10] ;
  11. c : char ;
  12. procedure p ;
  13. var
  14. l : string[6] ;
  15. begin
  16. l := 'abc' ;
  17. writeln (l[1], l[2], l[3]) ;
  18. g[2] := l[3]
  19. end ;
  20. begin
  21. g := 'hello' ;
  22. writeln (g[1], g[2], g[3]) ;
  23. c := g[5] ;
  24. writeln (c) ;
  25. g[1] := 'H' ;
  26. writeln (g) ;
  27. p ;
  28. writeln (g)
  29. end.