FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String question

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.     Forum Index -> DWT
View previous topic :: View next topic  
Author Message
brad
Site Admin


Joined: 22 Feb 2004
Posts: 490
Location: Atlanta, GA USA

PostPosted: Sat Jul 03, 2004 1:16 am    Post subject: String question Reply with quote

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
View user's profile Send private message
Blandger



Joined: 21 May 2004
Posts: 50
Location: Ukraine, Kharkov

PostPosted: Sat Jul 03, 2004 4:11 am    Post subject: Re: String question Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.     Forum Index -> DWT All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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