Следующее является, вероятно, не самым опрятным путем, но это работает:
1> lists:flatten(io_lib:format("~p", [35365])).
"35365"
РЕДАКТИРОВАНИЕ: я нашел, что следующая функция пригождается:
%% string_format/2
%% Like io:format except it returns the evaluated string rather than write
%% it to standard output.
%% Parameters:
%% 1. format string similar to that used by io:format.
%% 2. list of values to supply to format string.
%% Returns:
%% Formatted string.
string_format(Pattern, Values) ->
lists:flatten(io_lib:format(Pattern, Values)).
РЕДАКТИРОВАНИЕ 2 (в ответ на комментарии): вышеупомянутая функция прибыла из небольшой программы, которую я записал некоторое время назад для изучения Erlang. Я искал строковую функцию форматирования и нашел поведение io_lib:format/2
в erl
парадоксальным, например:
1> io_lib:format("2 + 2 = ~p", [2+2]).
[50,32,43,32,50,32,61,32,"4"]
В то время, я не знал об 'автосглаживающемся' поведении устройств вывода, упомянутых @archaelus и так завершенных, что вышеупомянутое поведение не было тем, что я хотел.
Этим вечером, я вернулся к этой программе и заменил вызовы к эти string_format
функция выше с io_lib:format
. Единственными проблемами, которые это вызвало, были несколько тестов EUnit, которые перестали работать, потому что они ожидали сглаженную строку. Они были легко зафиксированы.
я соглашаюсь с @gleber и @womble, что использование этой функции является излишеством для преобразования целого числа к строке. Если это - все, в чем Вы нуждаетесь, используете integer_to_list/1
. KISS!
Из RFC2616 :
Этот метод (HEAD) может использоваться для получения метаинформация об объекте подразумевается запросом без передача самого объекта-тела. Этот метод часто используется для тестирования гипертекстовые ссылки для проверки действительности, доступность и недавние modification.
The reason why HEAD is preferred to GET is due to the absence of the message body in the response making it using in scenarios where you want to determine if the content has changed at all - a change in the last modified time or content length usually signifies this.
Also, a HEAD request will provide some information about the server setup (whether it is IIS/Apache etc.), unless the server was masked; of course, this is available in all responses, but HEAD is preferred especially when you don't know the size of the response. HEAD is also the easiest way to determine if a site is up or down; again the irrelevance of the message body makes HEAD the ideal candidate.
I'm not sure about this, but RSS/ATOM feed readers would use HEAD over GET to ascertain if the contents of the feed have changed.
It's mainly for browsers and proxies to determine whether they can use a cached copy of the web document without having to download the whole thing (which would rather defeat the purpose of a cache).