String convention

Hasan Aljudy hasan.aljudy at gmail.com
Sat Jul 1 14:25:14 PDT 2006


D strings are dynamic arrays.
The "length" does not limit anything. you can change it anytime anyhow.

char[] s = "....."; //some string

.
.
.

s.length = s.length + XYZ; //change the length of the array to whatever 
thing you like
s = "exxxaa"; //or like this

I can't think of any limitation.

P.S. Don't use printf with D. Use writef instead, and don't forget to 
import std.stdio

Niklas Ulvinge wrote:
> I could't find any info about it so I'm asking here...
> 
> I just looked at D and it sounds rather interesting.
> 
> Now to my Q:
> Strings in D starts with some data that is defining the length of the string.
> Why did they decide to use this aproach?
> What is this 'data' at the beginning of the string?
> 
> This has a limitation, strings can't be longer than 'data' allows.
> Is there a way around this?
> 
> 
> An idea, I got when I wrote a dynamic array (in C), was to use s[-1] as the size
> for array s (and s[-2] for capacity, but that isn't necesary here...).
> 
> Couldn't this be used with strings?
> Then this would work:
> string s = "IDK\0";
> printf("%s",s);
> 
> Niklas Ulvinge
> aka IDK wishes
> everyone happy
> programming!!!



More information about the Digitalmars-d mailing list