size of a string in bytes
    Nestor via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sat Jan 28 06:51:37 PST 2017
    
    
  
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 mystring2 = "A string of just 48 characters for testing 
size.";
   writeln(mystring1.sizeof);
   writeln( mystring2.sizeof);
}
In both cases the size is 8, so apparently sizeof is giving me 
just the default size of a string type and not the size of the 
variable in memory, which is what I want.
Ideas?
    
    
More information about the Digitalmars-d-learn
mailing list