Why Strings as Classes?
Benji Smith
dlanguage at benjismith.net
Tue Aug 26 03:06:30 PDT 2008
superdan wrote:
> Benji Smith Wrote:
>> A char[] is actually an array of UTF-8 encoded octets, where each
>> character may consume one or more consecutive elements of the array.
>> Retrieving the str.length property may or may not tell you how many
>> characters are in the string. And pretty much any code that tries to
>> iterate character-by-character through the array elements is
>> fundamentally broken.
>
> try this:
>
> foreach (dchar c; str)
> {
> process c
> }
Cool. I had no idea that was possible. I was doing this:
myFunction(T)(T[] array) {
foreach(T c; array) {
doStuff(c);
}
}
--benji
More information about the Digitalmars-d
mailing list