Re: size of a string in bytes

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Saturday, 28 January 2017 at 19:09:01 UTC, ag0aep6g wrote: In D, a `char` is a UTF-8 code unit. Its size is one byte, exactly and always. A `char` is not a "character" in the common meaning of the word. There's a more specialized word for "character" as a visual unit: grapheme. For

Re: size of a string in bytes

2017-01-28 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 28 January 2017 at 18:04:58 UTC, Nestor wrote: I believe I saw somewhere that in D a char was not neccesarrily the same as an ubyte because chars sometimes take more than one byte, In D, a `char` is a UTF-8 code unit. Its size is one byte, exactly and always. A `char` is not a

Re: size of a string in bytes

2017-01-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 28 January 2017 at 18:04:58 UTC, Nestor wrote: I believe I saw somewhere that in D a char was not neccesarrily the same as an ubyte because chars sometimes take more than Not true in the language, but the Phobos library does treat char and ubyte differently because of the

Re: size of a string in bytes

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Saturday, 28 January 2017 at 16:01:38 UTC, Ivan Kazmenko wrote: As said, the byte count is indeed string.length. The number of code points can be found by std.range.walkLength, but be aware it takes O(answer) time to compute. Example: - import std.range, std.stdio; void main () {

Re: size of a string in bytes

2017-01-28 Thread Ivan Kazmenko via Digitalmars-d-learn
On Saturday, 28 January 2017 at 15:32:33 UTC, Nestor wrote: I want to know variable size in memory. For example, say I have an UTF-8 string of only 2 characters, but each of them takes 2 bytes. string length would be 2, but the content of the string would take 4 bytes in memory (excluding

Re: size of a string in bytes

2017-01-28 Thread rikki cattermole via Digitalmars-d-learn
On 29/01/2017 4:32 AM, Nestor wrote: On Saturday, 28 January 2017 at 14:56:03 UTC, rikki cattermole wrote: On 29/01/2017 3:51 AM, Nestor wrote: Hi, One can get the length of a string easily, however since strings are UTF-8, sometimes characters take more than one byte. I would like to know

Re: size of a string in bytes

2017-01-28 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 28, 2017 at 03:32:33PM +, Nestor via Digitalmars-d-learn wrote: [...] > I do not want string lenth or code points. Perhaps I didn't explain > myselft. The .length property of a string is the number of bytes used to store the string. > I want to know variable size in memory. For

Re: size of a string in bytes

2017-01-28 Thread Nestor via Digitalmars-d-learn
On Saturday, 28 January 2017 at 14:56:03 UTC, rikki cattermole wrote: On 29/01/2017 3:51 AM, Nestor wrote: Hi, One can get the length of a string easily, however since strings are UTF-8, sometimes characters take more than one byte. I would like to know then how many bytes does a string

Re: size of a string in bytes

2017-01-28 Thread rikki cattermole via Digitalmars-d-learn
On 29/01/2017 3:51 AM, Nestor wrote: Hi, One can get the length of a string easily, however since strings are UTF-8, sometimes characters take more than one byte. I would like to know then how many bytes does a string take, but this code didn't work as I expected: import std.stdio; void main()

size of a string in bytes

2017-01-28 Thread Nestor via Digitalmars-d-learn
Hi, One can get the length of a string easily, however since strings are UTF-8, sometimes characters take more than one byte. I would like to know then how many bytes does a string take, but this code didn't work as I expected: import std.stdio; void main() { string mystring1; string