Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

represent a text-string?

String text
0
10 Posted

represent a text-string?

0

As a list of characters. You can write A = “hello world”. which is exactly the same as writing A = [104,101,108,108,111,32,119,111,114,108,100]. and also the same as writing A = [$h,$e,$l,$l,$o,$ ,$w,$o,$r,$l,$d]. Each character consumes 8 bytes of memory on a 32 bit machine (a 32 bit integer and a 32 bit pointer) and twice as much on 64 bit machines. Access to the nth. element takes O(n) time. Access to the first element takes O(1) time, as does prepending a character. The bit-syntax, which is described in the manual provides an alternative, but somewhat limited, way to represent strings compactly, for instance: 1> A = <<"this string consumes one byte per character">>. <<116,104,105,115,32,115,116,114,...>> 2> size(A). 43 3> <<_:8/binary,Q:3/binary,R/binary>> = A. <<116,104,105,115,32,115,116,114,...>> 4> Q. <<105,110,103>> 5> binary_to_list(Q).

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.