digitalmars.D.learn - What is the correct function or cast to compare an unprintable ASCII
- Gary Miller (10/10) Mar 28 2014 If I need to examine a byte in string for a specific ASCII value
- bearophile (8/9) Mar 28 2014 enum char block = 219;
- monarch_dodra (8/18) Mar 28 2014 219 is not an "ASCII Block". You can just do a search for 219 in
If I need to examine a byte in string for a specific ASCII value like string MyString; MyString = "Hello World" and I want to check a position in the string for a certain unprintable ASCII value like the ASCII Block 219 what is the recommended method for doing so if (MyString[0..1])== ???(219)) writeln("ASCII Block found") I know there's and easy lib function or cast somewhere but everywhere I've looked it's not jumping out at me.
Mar 28 2014
Gary Miller:if (MyString[0..1])== ???(219)) writeln("ASCII Block found")enum char block = 219; ... if (myString[i] == block) "ASCII Block found".writeln; Note that variable/function names in D start with a lower case. Bye, bearophile
Mar 28 2014
On Friday, 28 March 2014 at 15:33:32 UTC, Gary Miller wrote:If I need to examine a byte in string for a specific ASCII value like string MyString; MyString = "Hello World" and I want to check a position in the string for a certain unprintable ASCII value like the ASCII Block 219 what is the recommended method for doing so if (MyString[0..1])== ???(219)) writeln("ASCII Block found") I know there's and easy lib function or cast somewhere but everywhere I've looked it's not jumping out at me.219 is not an "ASCII Block". You can just do a search for 219 in your *byte* stream: auto b = ("hello" ~ cast(char)219 ~ "world").representation.canFind(219); The "representation" part *very* is important: Without it, you string will be interpreted as unicode, and there is *not* actually a 219 codepoint in there.
Mar 28 2014