mutable string
Adam Sansier via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 10 14:38:09 PDT 2016
On Sunday, 10 July 2016 at 21:26:29 UTC, Adam Sansier wrote:
> For example, I'm trying to compare a wchar buffer with a
> wstring using slices:
>
> x[0..$] == y[0..$]
>
> It fails. I think because x has length 1024. If do
>
> x[0..y.length] == str[0..y.length]
>
> it fails, also because y has length 1024(since it was generated
> from a buffer and the length wasn't set correctly).
>
> If I fix the length to the size of y, it passes, but isn't
> correct since it is a partial match.
>
> also, to lower fails but CharLowerBuff passes(the error in the
> previous post)
>
> //str = str.toLower();
> CharLowerBuff(cast(LPTSTR)str, str.length);
Using this code
import core.stdc.wchar_; // For wcslen.
wstring toWstring(wchar[] value)
{
return value ? cast(wstring)
value[0..wcslen(cast(wchar*)value)] : null;
}
works and sets the length. Must be a bug in to!wstring!
More information about the Digitalmars-d-learn
mailing list