Input 在埃菲尔铁塔中,如何读取空格分隔的输入?

Input 在埃菲尔铁塔中,如何读取空格分隔的输入?,input,stream,eiffel,Input,Stream,Eiffel,我不能真正使用Io.read\u integer,因为它只会忽略除 第一个数字 我可以使用Io.read_line来获得类似于15 14 59 86的内容。 我现在如何将这些拆分为整数 SavaScript已经分裂,C++有String String,有些类似的东西是理想的。 < P>如果你只使用一个空间,{String }类中有一个拆分方法。split方法的参数是{CHARACTER}而不是{STRING}。因此,您必须使用“”而不是。这里有一个小函数,可以实现我认为您需要的功能 split_

我不能真正使用Io.read\u integer,因为它只会忽略除 第一个数字

我可以使用Io.read_line来获得类似于15 14 59 86的内容。 我现在如何将这些拆分为整数


SavaScript已经分裂,C++有String String,有些类似的东西是理想的。

< P>如果你只使用一个空间,{String }类中有一个拆分方法。split方法的参数是{CHARACTER}而不是{STRING}。因此,您必须使用“”而不是。这里有一个小函数,可以实现我认为您需要的功能

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

如果只使用一个空格,{STRING}类中有一个split方法。split方法的参数是{CHARACTER}而不是{STRING}。因此,您必须使用“”而不是。这里有一个小函数,可以实现我认为您需要的功能

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

如果希望在整数之间允许多个空格、制表符等,可以使用Gobo库中的类{ST_SPLITTER}。以下是一个例子:

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

如果希望在整数之间允许多个空格、制表符等,可以使用Gobo库中的类{ST_SPLITTER}。以下是一个例子:

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