String range to dchar.
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 30 17:55:03 PDT 2014
On Friday, 31 October 2014 at 00:17:02 UTC, Samuel Pike wrote:
> Hi all.
>
> First time posting here. I recently downloaded the dmd compiler
> and started making a few exercises with the language. Nice
> language features but still somewhat confused with the library.
>
> If I use byDchar() over a "string" is there a possibility to
> get part of a character or is guaranteed that the entire visual
> character will be in the dchar?
>
> Also, is there a way to peek into a range? Maybe a range that
> buffers its items when calling peek()?
>
> Thank you
You should just be able to call the range's .front method, which
will do the decoding. However, calling .front on just a normal
string without using byDchar will also work, as front
automatically decodes by default.
void main()
{
string s = "中文汉字";
writeln(s[0]); //Prints '?'
writeln(s.front); //Prints '中'
}
More information about the Digitalmars-d-learn
mailing list