Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9317465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:53:08+00:00 2026-06-19T02:53:08+00:00

I am trying to write an Ada equivalent to the split() method in Java

  • 0

I am trying to write an Ada equivalent to the split() method in Java or C++. I am to intake a string and an integer and output two seperate string values. For example:
split of “hello” and 2 would return:
“The first part is he
and the second part is llo”

The code I have is as follows:

-- split.adb splits an input string about a specified position.
--
-- Input: Astring, a string,
--        Pos, an integer.
-- Precondition: pos is in Astring'Range.
-- Output: The substrings Astring(Astring'First..Pos) and
--                        Astring(Pos+1..Astring'Last).
--------------------------------------------------------------

with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Fixed;
use  Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Fixed;

procedure Split is

   EMPTY_STRING : String := "                                        ";

   Astring, Part1, Part2 : String := EMPTY_STRING;
   Pos, Chars_Read       : Natural;

   ------------------------------------------------
   -- Split() splits a string in two.           
   -- Receive: The_String, the string to be split,
   --          Position, the split index.        
   -- PRE: 0 < Position <= The_String.length(). 
   --     (Ada arrays are 1-relative by default)
   -- Passback: First_Part - the first substring,
   --           Last_Part - the second substring.
   ------------------------------------------------
   function Split(TheString : in String ; Pos : in Integer; Part1 : out String ; Part2     : out String)  return String is 
   begin
    Move(TheString(TheString'First .. Pos), Part1);
    Move(TheString(Pos .. TheString'Last), Part2);
    return Part1, Part2;
     end Split;



begin                                           -- Prompt for input
   Put("To split a string, enter the string: ");
   Get_Line(Astring, Chars_Read);
   Put("Enter the split position: ");
   Get(Pos);

   Split(Astring, Pos, Part1, Part2);

   Put("The first part is ");
   Put_Line(Part1);
   Put(" and the second part is ");
   Put_Line(Part2);

end Split;

The main part I am having trouble with is returning the two separate string values and in general the whole split() function. Any pointers or help is appreciated. Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:53:09+00:00Added an answer on June 19, 2026 at 2:53 am

    Instead of a function, consider making Split a procedure having two out parameters, as you’ve shown. Then decide if Pos is the last index of Part1 or the first index of Part2; I’ve chosen the latter.

    procedure Split(
       TheString : in String; Pos : in Integer;
       Part1 : out String; Part2 : out String) is 
    begin
       Move(TheString(TheString'First .. Pos - 1), Part1);
       Move(TheString(Pos .. TheString'Last), Part2);
    end Split;
    

    Note that String indexes are Positive:

    type String is array(Positive range <>) of Character;
    subtype Positive is Integer range 1 .. Integer'Last;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write a code that searches hash values for specific string's (input by
Trying to write a short method so that I can parse a string and
I'm trying write a test for a method that returns a java.sql.Connection to connect
Trying to write a chat, like on facebook, I wondered if two clients can
Trying to write the xml file with FileStream.BeginWrite() method but it gives me an
Trying to write a piece of code to compare two strings. If either are
I referred to this article http://www.codeproject.com/KB/security/DotNetCrypto.aspx and I am trying write an encrypted string
Trying to write a test for a helper method that uses acts_as_tree. Helper method
I'm trying write a java program to send live microphone data over UDP, then
I have been trying write a Mutually Exclusive CheckBox. There are two checkBoxes in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.