Thread overview | |||||
---|---|---|---|---|---|
|
November 25, 2018 Convert multibyte `string` to `dstring` | ||||
---|---|---|---|---|
| ||||
Hello. Is there a proper way to convert a string with multibyte characters into a dstring? Case scenario: string a = "abc😃123"; // a.length == 10 ("abc"==3 + "😃"==4 + "123"==3) dstring b = foo(a); // b.length = 7 ("abc"==3 + "😃"==1 + "123"==3) dstring foo(string str) { // code... } |
November 25, 2018 Re: Convert multibyte `string` to `dstring` | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vladimirs Nordholm | On Sunday, 25 November 2018 at 21:23:31 UTC, Vladimirs Nordholm wrote:
> Is there a proper way to convert a string with multibyte characters into a dstring?
void main() {
import std.conv : to;
import std.stdio : writeln;
string a = "abc😃123";
auto b = to!dstring(a);
assert(b.length == 7);
writeln(b);
}
|
November 25, 2018 Re: Convert multibyte `string` to `dstring` | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stanislav Blinov | On Sunday, 25 November 2018 at 21:33:15 UTC, Stanislav Blinov wrote:
> On Sunday, 25 November 2018 at 21:23:31 UTC, Vladimirs Nordholm wrote:
>
>> Is there a proper way to convert a string with multibyte characters into a dstring?
>
> void main() {
> import std.conv : to;
> import std.stdio : writeln;
> string a = "abc😃123";
> auto b = to!dstring(a);
> assert(b.length == 7);
> writeln(b);
> }
Oh! It was so simple.
Thank you so much Stanislav 👍
|
Copyright © 1999-2021 by the D Language Foundation