represent a text-string?
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
- Why did I get "syntax error" when I set a string which has space(s) and/or tab(s) in it to a text type variable using CLI even if I have used quote mark to quote the string?
- Can we change without restrictions the location of any key text string in the templates? Or there are predefined mandatory locations for them in the templates?
- How can I alter the space between characters drawing the text string?