digitalmars.D.learn - writefln not liking % in strings!?
- AEon (25/25) Mar 29 2005 Testing ASCII chars above 128 (testing my translation code), I wrote
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/9) Mar 29 2005 You just need to add a "%s" format, before the string itself...
- AEon (6/15) Mar 29 2005 Right, but since I am normally reading string from text files, a % would...
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.<=>
lmnopqrstuvwxyz{|}~
<=> []0123456789.<=>
lmnopqrstuvwxyz{|}~
<
printf dumps the translated chars as planned.
% 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:Right, but since I am normally reading string from text files, a % would require a converttion to %%.writefln on the other hand exits on the % character.Unless you write "%%", which is the way to output a % character.Ahh... ops... lazy me!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.:) AEon
Mar 29 2005








AEon <aeon2001 lycos.de>