Copy a string: Difference between revisions
Content added Content deleted
(Sort the languages) |
|||
Line 2: | Line 2: | ||
<div class="messagebox">This task is about [[copying a string]]. </div> |
<div class="messagebox">This task is about [[copying a string]]. </div> |
||
==[[Ada]]== |
|||
[[Category:Ada]] |
|||
Ada provides three diffferent kinds of strings. The String type is a fixed length string. The Bounded_String type is a string with variable length up to a specified maximum size. The Unbounded_String type is a variable length string with no specified maximum size. The Bounded_String type behaves a lot like C strings, while the Unbounded_String type behaves a lot like the C++ String class. |
|||
===Fixed Length String Copying.=== |
|||
Src : String := "Hello"; |
|||
Dest : String := Src; |
|||
Ada provides the ability to manipulate slices of strings. |
|||
Src : String "Rosetta Stone"; |
|||
Dest : String := Src(1..7); -- Assigns "Rosetta" to Dest |
|||
Dest2 : String := Src(9..13); -- Assigns "Stone" to Dest2 |
|||
===Bounded Length String Copying=== |
|||
-- Instantiate the generic package Ada.Strings.Bounded.Generic_Bounded_Length with a maximum length of 80 characters |
|||
package Flexible_String is new Ada.Strings.Bounded.Generic_Bounded_Length(80); |
|||
use Flexible_String; |
|||
Src : Bounded_String := To_Bounded_String("Hello"); |
|||
Dest : Bounded_String := Src; |
|||
Ada Bounded_String type provides a number of functions for dealing with slices. |
|||
=== Unbounded Length String Copying=== |
|||
-- The package Ada.Strings.Unbounded contains the definition of the Unbounded_String type and all its methods |
|||
Src : Unbounded_String := To_Unbounded_String("Hello"); |
|||
Dest : Unbounded_String := Src; |
|||
==[[BASIC]]== |
==[[BASIC]]== |
||
[[Category:BASIC]] |
[[Category:BASIC]] |