Как я могу разделить двоичный файл в erlang

Если вы хотите получить 0 и 1, вы можете легко использовать метод jQuery map (), чтобы получить состояние флажков в каждой строке.

var table = $("table tbody")  // reference the table
table.on("change", "input:checkbox", function () {  // listen for checkbox being checked
  var result = table.find("tr")  // find the table rows
    .map( function () {  // loop over to create an array of the rows
      return $(this).find("input:checkbox")  // find the checkboxes in the row
        .map(function () {    // loop over and create array of the checkbox state
          return this.checked ? "1" : "0"  // if checked it is 1, else 0
        }).get().join("")  // change the array into a string of 0 and 1's
    }).get().join("<br/>")  // combine the array lines on the page
  $("#out").html(result)  // display the  result
}).find('input:checkbox:eq(0)').change();  // trigger change on first checkox so code runs
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tbody>
    <tr>
      <td><input type="checkbox" checked/></td>
      <td><input type="checkbox" /></td>
      <td><input type="checkbox" /></td>
      <td><input type="checkbox" /></td>
    </tr>
    <tr>
      <td><input type="checkbox" /></td>
      <td><input type="checkbox" checked/></td>
      <td><input type="checkbox" /></td>
      <td><input type="checkbox" /></td>
    </tr>
    <tr>
      <td><input type="checkbox" /></td>
      <td><input type="checkbox" checked/></td>
      <td><input type="checkbox" checked/></td>
      <td><input type="checkbox" /></td>
    </tr>
    <tr>
      <td><input type="checkbox" /></td>
      <td><input type="checkbox" /></td>
      <td><input type="checkbox" /></td>
      <td><input type="checkbox" checked/></td>
    </tr>
  </tbody>
</table>
<div id="out"></div>

9
задан Haldun 9 January 2009 в 13:58
поделиться

3 ответа

Нет никакой текущей функции OTP, которая является эквивалентом lists:split/2 это работает над двоичной строкой. Пока EEP-9 не обнародован, Вы могли бы записать двоичную функцию разделения как:

split(Binary, Chars) ->
    split(Binary, Chars, 0, 0, []).

split(Bin, Chars, Idx, LastSplit, Acc)
  when is_integer(Idx), is_integer(LastSplit) ->
    Len = (Idx - LastSplit),
    case Bin of
        <<_:LastSplit/binary,
         This:Len/binary,
         Char,
         _/binary>> ->
            case lists:member(Char, Chars) of
                false ->
                    split(Bin, Chars, Idx+1, LastSplit, Acc);
                true ->
                    split(Bin, Chars, Idx+1, Idx+1, [This | Acc])
            end;
        <<_:LastSplit/binary,
         This:Len/binary>> ->
            lists:reverse([This | Acc]);
        _ ->
            lists:reverse(Acc)
    end.
3
ответ дан 4 December 2019 в 06:27
поделиться

Существует приблизительно на 15% более быстрая версия двоичного разделения, работающего в R12B:

split2(Bin, Chars) ->
    split2(Chars, Bin, 0, []).

split2(Chars, Bin, Idx, Acc) ->
    case Bin of
        <<This:Idx/binary, Char, Tail/binary>> ->
            case lists:member(Char, Chars) of
                false ->
                    split2(Chars, Bin, Idx+1, Acc);
                true ->
                    split2(Chars, Tail, 0, [This|Acc])
            end;
        <<This:Idx/binary>> ->
            lists:reverse(Acc, [This])
    end.

Если Вы используете R11B или более старое использование archaelus версия вместо этого.

Вышеупомянутый код быстрее на станд. Байт-код ЛУЧА только, не в HiPE, существует оба почти то же.

Править: Отметьте этот код obsoleted новым двоичным файлом модуля начиная с R14B. Использовать binary:split(Bin, <<".">>, [global]). вместо этого.

4
ответ дан 4 December 2019 в 06:27
поделиться

Вот один путь:

re:split(<<"Hello.world.howdy?">>, "\\.").
3
ответ дан 4 December 2019 в 06:27
поделиться
Другие вопросы по тегам:

Похожие вопросы: