How would one read space separated input in Eiffel?











up vote
1
down vote

favorite












I can't really use Io.read_integer as that just ignores everything except
the first number.



I can use Io.read_line to get something like 15 14 59 86.
How would I split these into integers now?



Javascript has split(), C++ has stringstream, something similar would be ideal.










share|improve this question


























    up vote
    1
    down vote

    favorite












    I can't really use Io.read_integer as that just ignores everything except
    the first number.



    I can use Io.read_line to get something like 15 14 59 86.
    How would I split these into integers now?



    Javascript has split(), C++ has stringstream, something similar would be ideal.










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I can't really use Io.read_integer as that just ignores everything except
      the first number.



      I can use Io.read_line to get something like 15 14 59 86.
      How would I split these into integers now?



      Javascript has split(), C++ has stringstream, something similar would be ideal.










      share|improve this question













      I can't really use Io.read_integer as that just ignores everything except
      the first number.



      I can use Io.read_line to get something like 15 14 59 86.
      How would I split these into integers now?



      Javascript has split(), C++ has stringstream, something similar would be ideal.







      input stream eiffel






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 10:01









      Legolas

      255




      255
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          If you use only one space, there is a split method in the {STRING} class. The argument of the split method is a {CHARACTER} instead of a {STRING}. So, you have to use ' ' instead of " ". Here is a little function that do what I think you want.



          split_to_integer_list(a_string:STRING):ARRAYED_LIST[INTEGER]
          -- Convert `a_string', a space separated list of integer
          -- into a {LIST} of {INTEGER}
          local
          l_split:LIST[STRING]
          do
          l_split := a_string.split (' ')
          create Result.make (a_string.count)
          across l_split as la_split loop
          if la_split.item.is_integer then
          Result.extend(la_split.item.to_integer)
          end
          end
          end





          share|improve this answer




























            up vote
            2
            down vote













            In case you want to allow several spaces, tabs, etc. between the integers, you can use the class {ST_SPLITTER} from the Gobo library. Here is an example:



            local
            l_line: STRING
            l_splitter: ST_SPLITTER
            l_list: DS_LINKED_LIST [INTEGER]
            do
            io.read_line
            l_line := io.last_string
            create l_list.make
            create l_splitter.make_with_separators (" %T")
            across l_splitter.split (l_line) as l_split loop
            if l_split.item.is_integer then
            l_list.put_last (l_split.item.to_integer)
            end
            end





            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247600%2fhow-would-one-read-space-separated-input-in-eiffel%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote



              accepted










              If you use only one space, there is a split method in the {STRING} class. The argument of the split method is a {CHARACTER} instead of a {STRING}. So, you have to use ' ' instead of " ". Here is a little function that do what I think you want.



              split_to_integer_list(a_string:STRING):ARRAYED_LIST[INTEGER]
              -- Convert `a_string', a space separated list of integer
              -- into a {LIST} of {INTEGER}
              local
              l_split:LIST[STRING]
              do
              l_split := a_string.split (' ')
              create Result.make (a_string.count)
              across l_split as la_split loop
              if la_split.item.is_integer then
              Result.extend(la_split.item.to_integer)
              end
              end
              end





              share|improve this answer

























                up vote
                3
                down vote



                accepted










                If you use only one space, there is a split method in the {STRING} class. The argument of the split method is a {CHARACTER} instead of a {STRING}. So, you have to use ' ' instead of " ". Here is a little function that do what I think you want.



                split_to_integer_list(a_string:STRING):ARRAYED_LIST[INTEGER]
                -- Convert `a_string', a space separated list of integer
                -- into a {LIST} of {INTEGER}
                local
                l_split:LIST[STRING]
                do
                l_split := a_string.split (' ')
                create Result.make (a_string.count)
                across l_split as la_split loop
                if la_split.item.is_integer then
                Result.extend(la_split.item.to_integer)
                end
                end
                end





                share|improve this answer























                  up vote
                  3
                  down vote



                  accepted







                  up vote
                  3
                  down vote



                  accepted






                  If you use only one space, there is a split method in the {STRING} class. The argument of the split method is a {CHARACTER} instead of a {STRING}. So, you have to use ' ' instead of " ". Here is a little function that do what I think you want.



                  split_to_integer_list(a_string:STRING):ARRAYED_LIST[INTEGER]
                  -- Convert `a_string', a space separated list of integer
                  -- into a {LIST} of {INTEGER}
                  local
                  l_split:LIST[STRING]
                  do
                  l_split := a_string.split (' ')
                  create Result.make (a_string.count)
                  across l_split as la_split loop
                  if la_split.item.is_integer then
                  Result.extend(la_split.item.to_integer)
                  end
                  end
                  end





                  share|improve this answer












                  If you use only one space, there is a split method in the {STRING} class. The argument of the split method is a {CHARACTER} instead of a {STRING}. So, you have to use ' ' instead of " ". Here is a little function that do what I think you want.



                  split_to_integer_list(a_string:STRING):ARRAYED_LIST[INTEGER]
                  -- Convert `a_string', a space separated list of integer
                  -- into a {LIST} of {INTEGER}
                  local
                  l_split:LIST[STRING]
                  do
                  l_split := a_string.split (' ')
                  create Result.make (a_string.count)
                  across l_split as la_split loop
                  if la_split.item.is_integer then
                  Result.extend(la_split.item.to_integer)
                  end
                  end
                  end






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 12 at 0:55









                  Louis M

                  49124




                  49124
























                      up vote
                      2
                      down vote













                      In case you want to allow several spaces, tabs, etc. between the integers, you can use the class {ST_SPLITTER} from the Gobo library. Here is an example:



                      local
                      l_line: STRING
                      l_splitter: ST_SPLITTER
                      l_list: DS_LINKED_LIST [INTEGER]
                      do
                      io.read_line
                      l_line := io.last_string
                      create l_list.make
                      create l_splitter.make_with_separators (" %T")
                      across l_splitter.split (l_line) as l_split loop
                      if l_split.item.is_integer then
                      l_list.put_last (l_split.item.to_integer)
                      end
                      end





                      share|improve this answer

























                        up vote
                        2
                        down vote













                        In case you want to allow several spaces, tabs, etc. between the integers, you can use the class {ST_SPLITTER} from the Gobo library. Here is an example:



                        local
                        l_line: STRING
                        l_splitter: ST_SPLITTER
                        l_list: DS_LINKED_LIST [INTEGER]
                        do
                        io.read_line
                        l_line := io.last_string
                        create l_list.make
                        create l_splitter.make_with_separators (" %T")
                        across l_splitter.split (l_line) as l_split loop
                        if l_split.item.is_integer then
                        l_list.put_last (l_split.item.to_integer)
                        end
                        end





                        share|improve this answer























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          In case you want to allow several spaces, tabs, etc. between the integers, you can use the class {ST_SPLITTER} from the Gobo library. Here is an example:



                          local
                          l_line: STRING
                          l_splitter: ST_SPLITTER
                          l_list: DS_LINKED_LIST [INTEGER]
                          do
                          io.read_line
                          l_line := io.last_string
                          create l_list.make
                          create l_splitter.make_with_separators (" %T")
                          across l_splitter.split (l_line) as l_split loop
                          if l_split.item.is_integer then
                          l_list.put_last (l_split.item.to_integer)
                          end
                          end





                          share|improve this answer












                          In case you want to allow several spaces, tabs, etc. between the integers, you can use the class {ST_SPLITTER} from the Gobo library. Here is an example:



                          local
                          l_line: STRING
                          l_splitter: ST_SPLITTER
                          l_list: DS_LINKED_LIST [INTEGER]
                          do
                          io.read_line
                          l_line := io.last_string
                          create l_list.make
                          create l_splitter.make_with_separators (" %T")
                          across l_splitter.split (l_line) as l_split loop
                          if l_split.item.is_integer then
                          l_list.put_last (l_split.item.to_integer)
                          end
                          end






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 12 at 8:46









                          Eric Bezault

                          213




                          213






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247600%2fhow-would-one-read-space-separated-input-in-eiffel%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Xamarin.iOS Cant Deploy on Iphone

                              Glorious Revolution

                              Dulmage-Mendelsohn matrix decomposition in Python