comp.lang.ada
 help / color / mirror / Atom feed
* Can I convert a string of letters into an array?
@ 2012-03-06  1:46 Will
  2012-03-06  2:22 ` Shark8
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Will @ 2012-03-06  1:46 UTC (permalink / raw)


Hey There,

How do I convert a string of letters into an array? I am not sure how to sort the letters in the form of a string but I know how to do it using an array.  Then how do I convert that array back to a string after I am done sorting it?  

Thanks a bunch,

Will



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  1:46 Can I convert a string of letters into an array? Will
@ 2012-03-06  2:22 ` Shark8
  2012-03-06  2:58 ` Jeffrey Carter
  2012-03-06  3:13 ` Will
  2 siblings, 0 replies; 15+ messages in thread
From: Shark8 @ 2012-03-06  2:22 UTC (permalink / raw)


On Monday, March 5, 2012 7:46:15 PM UTC-6, Will wrote:
> Hey There,
> 
> How do I convert a string of letters into an array? I am not sure how to sort the letters in the form of a string but I know how to do it using an array.  Then how do I convert that array back to a string after I am done sorting it?  
> 
> Thanks a bunch,
> 
> Will

You don't need to, an Ada String already is an array.
   Type String is array ( positive range <> ) of Standard.Character;



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  1:46 Can I convert a string of letters into an array? Will
  2012-03-06  2:22 ` Shark8
@ 2012-03-06  2:58 ` Jeffrey Carter
  2012-03-06  3:10   ` Will
  2012-03-06  3:13 ` Will
  2 siblings, 1 reply; 15+ messages in thread
From: Jeffrey Carter @ 2012-03-06  2:58 UTC (permalink / raw)


On 03/05/2012 06:46 PM, Will wrote:
>
> How do I convert a string of letters into an array? I am not sure how to sort
> the letters in the form of a string but I know how to do it using an array.
> Then how do I convert that array back to a string after I am done sorting
> it?

You could instantiate Ada.Containers.Generic_Array_Sort for the array type String.

-- 
Jeff Carter
"Sir Lancelot saves Sir Gallahad from almost certain temptation."
Monty Python & the Holy Grail
69



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  2:58 ` Jeffrey Carter
@ 2012-03-06  3:10   ` Will
  2012-03-06  4:51     ` John B. Matthews
                       ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Will @ 2012-03-06  3:10 UTC (permalink / raw)


On Monday, March 5, 2012 9:58:46 PM UTC-5, Jeffrey Carter wrote:
> On 03/05/2012 06:46 PM, Will wrote:
> >
> > How do I convert a string of letters into an array? I am not sure how to sort
> > the letters in the form of a string but I know how to do it using an array.
> > Then how do I convert that array back to a string after I am done sorting
> > it?
> 
> You could instantiate Ada.Containers.Generic_Array_Sort for the array type String.
> 
> -- 
> Jeff Carter
> "Sir Lancelot saves Sir Gallahad from almost certain temptation."
> Monty Python & the Holy Grail
> 69

Jeff, I am a beginner at Ada, so I have no idea what you mean by that ha ha?



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  1:46 Can I convert a string of letters into an array? Will
  2012-03-06  2:22 ` Shark8
  2012-03-06  2:58 ` Jeffrey Carter
@ 2012-03-06  3:13 ` Will
  2012-03-06  8:29   ` Ludovic Brenta
       [not found]   ` <zLednfMxUtyBtsvSnZ2dnUVZ_oSdnZ2d@earthlink.com>
  2 siblings, 2 replies; 15+ messages in thread
From: Will @ 2012-03-06  3:13 UTC (permalink / raw)


On Monday, March 5, 2012 8:46:15 PM UTC-5, Will wrote:
> Hey There,
> 
> How do I convert a string of letters into an array? I am not sure how to sort the letters in the form of a string but I know how to do it using an array.  Then how do I convert that array back to a string after I am done sorting it?  
> 
> Thanks a bunch,
> 
> Will

Here is the problem, "Write a procedure that takes in a string of 'B' and 'G' characters.  The procedure should rearrange the letters into an alternating 'B'-'G' pattern that continues until the less numerous letter runs out.  Assume the string only contains 'B's and 'G's; that the patter you create always starts with a 'B'; and that the string will always contain at least 1 of each letter.  For example: "BBBBGGGBG" becomes "BGBGBGBGB", and "GGBG" becomes "BGGG"."



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  3:10   ` Will
@ 2012-03-06  4:51     ` John B. Matthews
  2012-03-06  5:00       ` John B. Matthews
  2012-03-06  6:29     ` Jeffrey Carter
  2012-03-08  9:48     ` tonyg
  2 siblings, 1 reply; 15+ messages in thread
From: John B. Matthews @ 2012-03-06  4:51 UTC (permalink / raw)


In article 
<3994111.4442.1331003406394.JavaMail.geo-discussion-forums@vblb5>,
 Will <willmann817@gmail.com> wrote:

> On Monday, March 5, 2012 9:58:46 PM UTC-5, Jeffrey Carter wrote:
> > On 03/05/2012 06:46 PM, Will wrote:
> > >
> > > How do I convert a string of letters into an array? I am not sure 
> > > how to sort the letters in the form of a string but I know how to 
> > > do it using an array. Then how do I convert that array back to a 
> > > string after I am done sorting it?
> > 
> > You could instantiate Ada.Containers.Generic_Array_Sort for the 
> > array type String.
> 
> Jeff, I am a beginner at Ada, so I have no idea what you mean by that ha ha?

Jeff: In Ada, a String is an array of Character:

   type String is array(Positive range <>) of Character;

You can create an instance of Generic_Array_Sort that sorts the 
Characters in a String like this:

   procedure Sort is new Ada.Containers.Generic_Array_Sort(
      Index_Type   => Positive,
      Element_Type => Character,
      Array_Type   => String);

There's a complete example here:

<http://home.roadrunner.com/~jbmatthews/jumble.html>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  4:51     ` John B. Matthews
@ 2012-03-06  5:00       ` John B. Matthews
  0 siblings, 0 replies; 15+ messages in thread
From: John B. Matthews @ 2012-03-06  5:00 UTC (permalink / raw)


In article <nospam-22AFE6.23512205032012@news.aioe.org>,
 "John B. Matthews" <nospam@nospam.invalid> wrote:

> In article 
> <3994111.4442.1331003406394.JavaMail.geo-discussion-forums@vblb5>,
>  Will <willmann817@gmail.com> wrote:
> 
> > On Monday, March 5, 2012 9:58:46 PM UTC-5, Jeffrey Carter wrote:
> > > On 03/05/2012 06:46 PM, Will wrote:
> > > >
> > > > How do I convert a string of letters into an array? I am not sure 
> > > > how to sort the letters in the form of a string but I know how to 
> > > > do it using an array. Then how do I convert that array back to a 
> > > > string after I am done sorting it?
> > > 
> > > You could instantiate Ada.Containers.Generic_Array_Sort for the 
> > > array type String.
> > 
> > Jeff, I am a beginner at Ada, so I have no idea what you mean by that ha ha?
> 
> Jeff: In Ada, a String is an array of Character:
> 
>    type String is array(Positive range <>) of Character;
> 
> You can create an instance of Generic_Array_Sort that sorts the 
> Characters in a String like this:
> 
>    procedure Sort is new Ada.Containers.Generic_Array_Sort(
>       Index_Type   => Positive,
>       Element_Type => Character,
>       Array_Type   => String);
> 
> There's a complete example here:
> 
> <http://home.roadrunner.com/~jbmatthews/jumble.html>

D'oh, I meant to address Will, of course.

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  3:10   ` Will
  2012-03-06  4:51     ` John B. Matthews
@ 2012-03-06  6:29     ` Jeffrey Carter
  2012-03-06  7:51       ` anon
  2012-03-08  9:48     ` tonyg
  2 siblings, 1 reply; 15+ messages in thread
From: Jeffrey Carter @ 2012-03-06  6:29 UTC (permalink / raw)


On 03/05/2012 08:10 PM, Will wrote:
>
> Jeff, I am a beginner at Ada, so I have no idea what you mean by that ha ha?

That's OK. It's apparent from your post with the problem statement that you 
don't want to sort a String anyway.

-- 
Jeff Carter
"Sir Lancelot saves Sir Gallahad from almost certain temptation."
Monty Python & the Holy Grail
69



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  6:29     ` Jeffrey Carter
@ 2012-03-06  7:51       ` anon
  0 siblings, 0 replies; 15+ messages in thread
From: anon @ 2012-03-06  7:51 UTC (permalink / raw)


Yes, it possible!

with Ada.Text_IO ;
procedure a is

  A : String ( 1 .. 4 ) ;

  B : Character := 'T' ;
begin
  A := ( 't', 'e', 's', 't' ) ;
  Ada.Text_IO.Put_Line ( A ) ;

  A := ( B, 'e', 's', 't' ) ;
  Ada.Text_IO.Put_Line ( A ) ;
  
end a ;

In <jj4b0f$fj5$1@tornado.tornevall.net>, Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:
>On 03/05/2012 08:10 PM, Will wrote:
>>
>> Jeff, I am a beginner at Ada, so I have no idea what you mean by that ha ha?
>
>That's OK. It's apparent from your post with the problem statement that you 
>don't want to sort a String anyway.
>
>-- 
>Jeff Carter
>"Sir Lancelot saves Sir Gallahad from almost certain temptation."
>Monty Python & the Holy Grail
>69




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  3:13 ` Will
@ 2012-03-06  8:29   ` Ludovic Brenta
       [not found]   ` <zLednfMxUtyBtsvSnZ2dnUVZ_oSdnZ2d@earthlink.com>
  1 sibling, 0 replies; 15+ messages in thread
From: Ludovic Brenta @ 2012-03-06  8:29 UTC (permalink / raw)


Will wrote on comp.lang.ada:
> Here is the problem, "Write a procedure that takes in a string of 'B'
> and 'G' characters.  The procedure should rearrange the letters into
> an alternating 'B'-'G' pattern that continues until the less numerous
> letter runs out.  Assume the string only contains 'B's and 'G's; that
> the patter you create always starts with a 'B'; and that the string
> will always contain at least 1 of each letter.  For example:
> "BBBBGGGBG" becomes "BGBGBGBGB", and "GGBG" becomes "BGGG"."

As others have said, a string is, by definition, an array of Characters,
so you don't need to "convert a string of letters into an array".  Your
teacher should have already explained to you how to access individual
elements (Characters) in an array (String), so this homework assignment
should be no challenge to you.  To get you started, here is a skeleton
where you "just" need to fill in the blanks:

function Rearrange (Input : in String) is
   Result : String (Input'Range);
   Number_Of_Bs : Natural;
   Number_Of_Gs : Natural;
begin
   ...
   return Result;
end Rearrange;

I hope I didn't say too much...

-- 
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
       [not found]   ` <zLednfMxUtyBtsvSnZ2dnUVZ_oSdnZ2d@earthlink.com>
@ 2012-03-07 10:39     ` Jacob Sparre Andersen
  0 siblings, 0 replies; 15+ messages in thread
From: Jacob Sparre Andersen @ 2012-03-07 10:39 UTC (permalink / raw)


Dennis Lee Bieber wrote:

> 	That's all? Given the specifications you don't even need to
> "rearrange" the contents. All you need is the total length, and a pass
> over the string to count how many "B"s appear in it. That gives you
> the information of how many "G"s are in it (since the spec says you
> don't have to worry about any other characters). Given m-B, n-G, a
> moderately simple loop can be used to emit alternating BG pairs until
> the shorter one has expired, then just emit enough of the remaining
> letter to fill out the required length.

Why not just use Ada.Strings.Fixed.Count and Ada.Strings.Fixed."*".

Jacob
-- 
"Those who will not reason, are bigots,
 those who cannot, are fools, and
 those who dare not, are slaves."



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-06  3:10   ` Will
  2012-03-06  4:51     ` John B. Matthews
  2012-03-06  6:29     ` Jeffrey Carter
@ 2012-03-08  9:48     ` tonyg
  2012-03-08 11:30       ` Simon Wright
  2 siblings, 1 reply; 15+ messages in thread
From: tonyg @ 2012-03-08  9:48 UTC (permalink / raw)


On Mar 6, 3:10 am, Will <willmann...@gmail.com> wrote:
> On Monday, March 5, 2012 9:58:46 PM UTC-5, Jeffrey Carter wrote:
> > On 03/05/2012 06:46 PM, Will wrote:
>
> > > How do I convert a string of letters into an array? I am not sure how to sort
> > > the letters in the form of a string but I know how to do it using an array.
> > > Then how do I convert that array back to a string after I am done sorting
> > > it?
>
> > You could instantiate Ada.Containers.Generic_Array_Sort for the array type String.
>
> > --
> > Jeff Carter
> > "Sir Lancelot saves Sir Gallahad from almost certain temptation."
> > Monty Python & the Holy Grail
> > 69
>
> Jeff, I am a beginner at Ada, so I have no idea what you mean by that ha ha?

I've been using Ada since 1987 (not all the time) and I'm still
finding useful stuff I didn't know about it. I'm also still ask stuff
in here pretty regularly :)



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-08  9:48     ` tonyg
@ 2012-03-08 11:30       ` Simon Wright
  2012-03-08 13:06         ` mockturtle
  0 siblings, 1 reply; 15+ messages in thread
From: Simon Wright @ 2012-03-08 11:30 UTC (permalink / raw)


tonyg <tonythegair@gmail.com> writes:

> On Mar 6, 3:10 am, Will <willmann...@gmail.com> wrote:

>> Jeff, I am a beginner at Ada, so I have no idea what you mean by that
>> ha ha?
>
> I've been using Ada since 1987 (not all the time) and I'm still
> finding useful stuff I didn't know about it. I'm also still ask stuff
> in here pretty regularly :)

Me too. Google is your friend; enter Ada.Containers.Generic_Array_Sort &
look at the second hit.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-08 11:30       ` Simon Wright
@ 2012-03-08 13:06         ` mockturtle
  2012-03-08 14:04           ` Simon Wright
  0 siblings, 1 reply; 15+ messages in thread
From: mockturtle @ 2012-03-08 13:06 UTC (permalink / raw)


On Thursday, March 8, 2012 12:30:06 PM UTC+1, Simon Wright wrote:
> tonyg writes:
> 
> > On Mar 6, 3:10 am, Will <willmann...@gmail.com> wrote:
> 
> >> Jeff, I am a beginner at Ada, so I have no idea what you mean by that
> >> ha ha?
> >
> > I've been using Ada since 1987 (not all the time) and I'm still
> > finding useful stuff I didn't know about it. I'm also still ask stuff
> > in here pretty regularly :)
> 
> Me too. Google is your friend; enter Ada.Containers.Generic_Array_Sort &
> look at the second hit.

Why bothering with Google? Just check paragraph A.18.16 of our beloved RM ;-). 




^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Can I convert a string of letters into an array?
  2012-03-08 13:06         ` mockturtle
@ 2012-03-08 14:04           ` Simon Wright
  0 siblings, 0 replies; 15+ messages in thread
From: Simon Wright @ 2012-03-08 14:04 UTC (permalink / raw)


mockturtle <framefritti@gmail.com> writes:

> On Thursday, March 8, 2012 12:30:06 PM UTC+1, Simon Wright wrote:
>> tonyg writes:
>> 
>> > On Mar 6, 3:10 am, Will <willmann...@gmail.com> wrote:
>> 
>> >> Jeff, I am a beginner at Ada, so I have no idea what you mean by
>> >> that ha ha?
>> >
>> > I've been using Ada since 1987 (not all the time) and I'm still
>> > finding useful stuff I didn't know about it. I'm also still ask
>> > stuff in here pretty regularly :)
>> 
>> Me too. Google is your friend; enter
>> Ada.Containers.Generic_Array_Sort & look at the second hit.
>
> Why bothering with Google? Just check paragraph A.18.16 of our beloved
> RM ;-).

True, but that Google route takes you to a working example.



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2012-03-08 14:04 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-06  1:46 Can I convert a string of letters into an array? Will
2012-03-06  2:22 ` Shark8
2012-03-06  2:58 ` Jeffrey Carter
2012-03-06  3:10   ` Will
2012-03-06  4:51     ` John B. Matthews
2012-03-06  5:00       ` John B. Matthews
2012-03-06  6:29     ` Jeffrey Carter
2012-03-06  7:51       ` anon
2012-03-08  9:48     ` tonyg
2012-03-08 11:30       ` Simon Wright
2012-03-08 13:06         ` mockturtle
2012-03-08 14:04           ` Simon Wright
2012-03-06  3:13 ` Will
2012-03-06  8:29   ` Ludovic Brenta
     [not found]   ` <zLednfMxUtyBtsvSnZ2dnUVZ_oSdnZ2d@earthlink.com>
2012-03-07 10:39     ` Jacob Sparre Andersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox