digitalmars.D.learn - writefln not liking % in strings!?
- AEon <aeon2001 lycos.de> Mar 29 2005
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> Mar 29 2005
- AEon <aeon2001 lycos.de> Mar 29 2005
Testing ASCII chars above 128 (testing my translation code), I wrote
this little test:
char[] test;
test.length=256;
for(int i=0; i<=255; i++)
test[i] = cast(char) i;
// Checks char by char, and offsets them to "good" chars
remove_q1_Color_Names(test);
printf("\nLine: >%.*s<\n\n",test[1..$]);
writefln("Line: >",test[1..$]);
This yields the following result fro printf:
Line: > []0123456789.<=>
!"#$%&'()*+,-./0123456789:;<=>? ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij
lmnopqrstuvwxyz{|}~
<=> []0123456789.<=>
!"#$%&'()*+,-./0123456789:;<=>? ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij
lmnopqrstuvwxyz{|}~
<
printf dumps the translated chars as planned.
Line: > []0123456789.<=> !"#$Error: std.format
% messes up code
writefln on the other hand exits on the % character.
This is more of a warning to the writefln fans. Avoid using it for
situations where a % *can* be part of a string you try to output. Ugly!
Back to prinft() for me again. Luckily when translating my code I kept
printf() most of the time.
AEon
Mar 29 2005
AEon wrote:writefln on the other hand exits on the % character.
Unless you write "%%", which is the way to output a % character.This is more of a warning to the writefln fans. Avoid using it for situations where a % *can* be part of a string you try to output. Ugly!
You just need to add a "%s" format, before the string itself... Reasons like this are exactly why I wrote std.stdio.writeln It doesn't have any such "special" characters, like % or so. --anders
Mar 29 2005
Anders F Björklund wrote:writefln on the other hand exits on the % character.
Unless you write "%%", which is the way to output a % character.
Right, but since I am normally reading string from text files, a % would require a converttion to %%.This is more of a warning to the writefln fans. Avoid using it for situations where a % *can* be part of a string you try to output. Ugly!
You just need to add a "%s" format, before the string itself...
Ahh... ops... lazy me!Reasons like this are exactly why I wrote std.stdio.writeln It doesn't have any such "special" characters, like % or so.
:) AEon
Mar 29 2005








AEon <aeon2001 lycos.de>