comp.lang.ada
 help / color / mirror / Atom feed
* Help me parse a long character
@ 1997-10-25  0:00 DHBemis
  1997-10-26  0:00 ` Tom Moran
  0 siblings, 1 reply; 6+ messages in thread
From: DHBemis @ 1997-10-25  0:00 UTC (permalink / raw)



This is an easy one I'm sure. I'm in my first semester of programming....

I'm trying to parse a 40-character long string. They are formatted in the
 following way:

LASTNAME^^^^^^^^^^^^^^^^^FIRSTNAME^^^^^^      <--- the variable Full_Name

I'm not sure how to parse it into to two separate variables, first_name and
 Last_name.

I used the get_line procedure to get the string, so I have the last_character
 position. How do I ignore the spaces in between?

Thanks !

Help




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

* Re: Help me parse a long character
  1997-10-25  0:00 DHBemis
@ 1997-10-26  0:00 ` Tom Moran
  1997-10-27  0:00   ` DHBemis
  0 siblings, 1 reply; 6+ messages in thread
From: Tom Moran @ 1997-10-26  0:00 UTC (permalink / raw)



Look up 'slices' in your book.




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

* Re: Help me parse a long character
  1997-10-26  0:00 ` Tom Moran
@ 1997-10-27  0:00   ` DHBemis
  0 siblings, 0 replies; 6+ messages in thread
From: DHBemis @ 1997-10-27  0:00 UTC (permalink / raw)



I figured it out... Thanks for all the input.




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

* Re: Help me parse a long character
@ 1997-11-03  0:00 Simon Johnston
  1997-11-03  0:00 ` Robert Dewar
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Johnston @ 1997-11-03  0:00 UTC (permalink / raw)



Use the Index function in Ada.Strings.Fixed, like so: the first bit will
get you the last name, and then the first name. You can then use the
resulting four values to substring your original to get two shorter
strings. Note this relies on at least one space between LASTNAME and
FIRSTNAME and a trailing space after FIRSTNAME - if this is not the case
then you'll have to add some code :)

   declare
      Start_Of_LASTNAME : Natural;
      End_Of_LASTNAME : Natural;
      Start_Of_FIRSTNAME : Natural;
      End_Of_FIRSTNAME : Natural;
   begin
      Start_Of_LASTNAME := Full_Name_String'First;
      End_Of_LASTNAME :=
Natural'Pred(Ada.Strings.Fixed.Index(Full_Name_String, " "));

      Start_Of_FIRSTNAME :=
Ada.Strings.Fixed.Index_Non_Blank(Full_Name_String(End_Of_LASTNAME ..
Full_Name_String'Last));
      End_Of_FIRSTNAME :=
Natural'Pred(Ada.Strings.Fixed.Index(Full_Name_String(Start_Of_FIRSTNAME ..
Full_Name_String'Last)));
   end ;

-----Original Message-----
From:   DHBemis [SMTP:dhbemis@AOL.COM]
Sent:   Saturday, October 25, 1997 8:48 PM
To:     INFO-ADA@LISTSERV.NODAK.EDU
Subject:        Help me parse a long character

This is an easy one I'm sure. I'm in my first semester of programming....

I'm trying to parse a 40-character long string. They are formatted in the
 following way:

LASTNAME^^^^^^^^^^^^^^^^^FIRSTNAME^^^^^^      <--- the variable Full_Name

I'm not sure how to parse it into to two separate variables, first_name and
 Last_name.

I used the get_line procedure to get the string, so I have the
last_character
 position. How do I ignore the spaces in between?

Thanks !

Help




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

* Re: Help me parse a long character
  1997-11-03  0:00 Help me parse a long character Simon Johnston
@ 1997-11-03  0:00 ` Robert Dewar
  0 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1997-11-03  0:00 UTC (permalink / raw)



Simon said

<<Use the Index function in Ada.Strings.Fixed, like so: the first bit will
get you the last name, and then the first name. You can then use the
resulting four values to substring your original to get two shorter
strings. Note this relies on at least one space between LASTNAME and
FIRSTNAME and a trailing space after FIRSTNAME - if this is not the case
then you'll have to add some code :)>>

If you are using GNAT, an interesting alternative is to use the pattern
matching routines provided in GNAT.Spitbol and its children. For a 
tutorial on the use of this facility, see file g-spipat.ads which
contains a 550 line section called "Pattern Matching Tutorial",
including some examples.

In general when using GNAT, be sure to be aware that more and more useful
stuff appears in the GNAT hierarchy in each release. Each of these packages
is designed to be fully documented int he corresponding spec file, so
browsing g-*.ads is well worth while.

Note that these are all GPL'ed packages, and thus can in some cases be used
with other Ada 95 compilers, but they are planned for use with GNAT, and in
several cases, including the pattern matching stuff, make use of implementation
dependent features (the use of Unrestricted_Access in particular is pretty
fundamental in GNAT.Spitbol.Patterns, both at the user level and at the
implementation level.

Robert Dewar
Ada Core Technologies

Note: For supported customers of ACT, the support fully extends to all
packages provided in the GNAT hierarchy.





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

* Re: Help me parse a long character
@ 1997-11-03  0:00 Marin David Condic, 561.796.8997, M/S 731-96
  0 siblings, 0 replies; 6+ messages in thread
From: Marin David Condic, 561.796.8997, M/S 731-96 @ 1997-11-03  0:00 UTC (permalink / raw)



DHBemis <dhbemis@AOL.COM> writes:
>This is an easy one I'm sure. I'm in my first semester of programming....
>
>I'm trying to parse a 40-character long string. They are formatted in the
> following way:
>
>LASTNAME^^^^^^^^^^^^^^^^^FIRSTNAME^^^^^^      <--- the variable Full_Name
>
>I'm not sure how to parse it into to two separate variables, first_name and
> Last_name.
>
>I used the get_line procedure to get the string, so I have the last_character
> position. How do I ignore the spaces in between?
>
    Without writing the code for you...

    You might try declaring a three-state enumeration type (last_name,
    intermediate_spaces, first_name) and declaring a variable of that
    type that starts out at "last_name" As your loop scans the array,
    it looks for spaces to change to the middle state and non-spaces
    to change to the last state. The state tells you where to store
    the characters.

    If you don't yet know about enumeration types, try a counter with
    values of "1" "2" and "3" - same thing.

    MDC

Marin David Condic, Senior Computer Engineer     Voice:     561.796.8997
Pratt & Whitney GESP, M/S 731-96, P.O.B. 109600  Fax:       561.796.4669
West Palm Beach, FL, 33410-9600                  Internet:  CONDICMA@PWFL.COM
===============================================================================
    "Having an open mind is nothing. The object of opening the mind, as
    of opening the mouth, is to shut it again on something solid."
        --  G.K. Chesterton
===============================================================================




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

end of thread, other threads:[~1997-11-03  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-03  0:00 Help me parse a long character Simon Johnston
1997-11-03  0:00 ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1997-11-03  0:00 Marin David Condic, 561.796.8997, M/S 731-96
1997-10-25  0:00 DHBemis
1997-10-26  0:00 ` Tom Moran
1997-10-27  0:00   ` DHBemis

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