View previous topic :: View next topic |
Author |
Message |
brad Site Admin
Joined: 22 Feb 2004 Posts: 490 Location: Atlanta, GA USA
|
Posted: Sat Jul 03, 2004 1:16 am Post subject: String question |
|
|
In trying to convert:
Code: |
wchar findMnemonic (String string) {
...
if (string.charAt (index) != '&') return string.charAt (index);
...
}
|
to D, I came up with this:
Code: |
if (string[index] != '&') return string[index];
|
BTW, String is aliased as wchar[] because Java strings are UTF-16.
My question is, if string[index] is a wchar, does comparing it to '&' really work? is '&' a wchar, too? _________________ I really like the vest! |
|
Back to top |
|
|
Blandger
Joined: 21 May 2004 Posts: 50 Location: Ukraine, Kharkov
|
Posted: Sat Jul 03, 2004 4:11 am Post subject: Re: String question |
|
|
brad wrote: | In trying to convert:
Code: |
if (string[index] != '&') return string[index];
|
My question is, if string[index] is a wchar, does comparing it to '&' really work? is '&' a wchar, too? |
Works quite well but prints (by 'printf') ugly.
Also it allows me assing ASCII symbols to string but doesn't allow 'russian symbols' there. For russian symbols it gives: "wcharTest.d(5): invalid UTF-8 sequence"
Try it:
Code: |
import std.c.stdio;
int main ( char [] [] args ) {
wchar[] testStr = "&a3&zRN&";
printf("Test string is '?.*s'\n", testStr);
for (int i=0; i < testStr.length; i++) {
wchar strAtPos = testStr[i];
if (strAtPos == '&') {
printf("symbols are equal\n");
} else {
printf("symbol are NOT equal\n");
}
}
return 1;
}
|
Also code
Code: | printf("symbols are equal '?.*s'\n", strAtPos); |
gives wrong output. _________________ Regards, Yuriy |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|