Copy a string: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
(→Pascal: fix non-standard example containing multiple mistakes) |
||
Line 1,963: | Line 1,963: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
''See also: [[#Delphi|Delphi]]'' |
|||
<syntaxhighlight lang="pascal">program |
<syntaxhighlight lang="pascal" highlight="9,13,15">program copyAString; |
||
⚫ | |||
{ The Extended Pascal `string` schema data type |
|||
type |
|||
is essentially a `packed array[1..capacity] of char`. } |
|||
source, destination: string(80); |
|||
pString = ^string; |
|||
⚫ | |||
source := 'Hello world!'; |
|||
⚫ | |||
{ In Pascal _whole_ array data type values can be copied by assignment. } |
|||
destination := source; |
|||
s1,s2 : string ; |
|||
{ Provided `source` is a _non-empty_ string value |
|||
pStr : pString ; |
|||
you can copy in Extended Pascal sub-ranges _of_ _string_ types, too. |
|||
Note, the sub-range notation is not permitted for a `bindable` data type. } |
|||
⚫ | |||
destination := source[1..length(source)]; |
|||
{ You can also employ Extended Pascal’s `writeStr` routine: } |
|||
/* direct copy */ |
|||
writeStr(destination, source); |
|||
s1 := 'Now is the time for all good men to come to the aid of their party.' |
|||
⚫ | |||
s2 := s1 ; |
|||
writeln(s1); |
|||
writeln(s2); |
|||
/* By Reference */ |
|||
pStr := @s1 ; |
|||
writeln(pStr^); |
|||
pStr := @s2 ; |
|||
writeln(pStr^); |
|||
⚫ | |||
=={{header|Perl}}== |
=={{header|Perl}}== |