Thread overview
converting wide to c
Dec 19, 2003
Lewis
Dec 19, 2003
Walter
Dec 19, 2003
Lewis
Dec 19, 2003
Lewis
Dec 19, 2003
J C Calvarese
Dec 19, 2003
Lewis
Dec 19, 2003
Walter
December 19, 2003
ok i looked thru the string functions an found toCharz() to convert a wide string to a null terminated string, but when i tried to use it it told me it wasnt appreciated :(  (depreciated lol) so then i of course i tried to write my own an failed miserably... would anyone care to give me a hint on how to make this work? or is there another function i can use somewhere... thanks

//Convert a wide string to a 'c' string
char[] WideToAscii(wchar[] WideArr) {
	
	int i = 0;
	int Count = 0;
	char[] CharArr;
	
	i.init;
	Count.init;
	
	if ( WideArr.length > 0 )  	{
		
           CharArr.length = (WideArr.length / 2) + 1;
	
            while ( i < WideArr.length )	{
	        CharArr[Count] = (char) WideArr[i];
	        i += 2;
	        Count += 1;
	    }

	}

  CharArr[CharArr.length - 1] = (char)r"0";
  return CharArr;

 }

:) yes i have a long way to go lol
December 19, 2003
Check out std.utf.toUTF8(wchar[]).

"Lewis" <dethbomb@hotmail.com> wrote in message news:brtfti$20j8$1@digitaldaemon.com...
> ok i looked thru the string functions an found toCharz() to convert a wide string to a null terminated string, but when i tried to use it it told me
it
> wasnt appreciated :(  (depreciated lol) so then i of course i tried to
write my
> own an failed miserably... would anyone care to give me a hint on how to
make
> this work? or is there another function i can use somewhere... thanks
>
> //Convert a wide string to a 'c' string
> char[] WideToAscii(wchar[] WideArr) {
>
> int i = 0;
> int Count = 0;
> char[] CharArr;
>
> i.init;
> Count.init;
>
> if ( WideArr.length > 0 )  {
>
>             CharArr.length = (WideArr.length / 2) + 1;
>
>              while ( i < WideArr.length ) {
>         CharArr[Count] = (char) WideArr[i];
>         i += 2;
>         Count += 1;
>     }
>
> }
>
>    CharArr[CharArr.length - 1] = (char)r"0";
>    return CharArr;
>
>   }
>
> :) yes i have a long way to go lol


December 19, 2003
Walter wrote:

> Check out std.utf.toUTF8(wchar[]).
> 

thanks walter, your the man!
December 19, 2003
wow i can see a bad habit starting, but how is it possible to have 3 functions with the same name? how do i specify which one to use (it just wants to use the first one and i get a type mismatch compile error) Do i have to comment out the ones that i dont want to use?

sorry if im being a pain
December 19, 2003
Lewis wrote:
> wow i can see a bad habit starting, but how is it possible to have 3 functions with the same name? 
It's okay.  They have 3 sets different argument litss: (char[]), (wchar[]), (dchar[]).

> how do i specify which one to use (it just wants to use the first one and i get a type mismatch compile error) Do i have to comment out the ones that i dont want to use?
No.  You shouldn't have to comment out anything in phobos.

I'm not sure what the problem is.  My blind guess is that you need to use a cast:

toUTF8(cast(wchar[]) "your string")
or
toUTF8(cast(wchar[]) str)

(By the way, it does help if you include a snippet of code.  Sometimes, the solution is obvious if we see it.)

> 
> sorry if im being a pain
Don't worry about it.  We've all starting programming in D fairly recently. :)


Justin
December 19, 2003
It picks one based on the type of the argument you supply to it.

"Lewis" <dethbomb@hotmail.com> wrote in message news:brtv0l$2mvh$1@digitaldaemon.com...
>
> wow i can see a bad habit starting, but how is it possible to have 3
functions
> with the same name? how do i specify which one to use (it just wants to
use the
> first one and i get a type mismatch compile error) Do i have to comment
out the
> ones that i dont want to use?
>
> sorry if im being a pain


December 19, 2003
J C Calvarese wrote:

> Lewis wrote:
> 
>> wow i can see a bad habit starting, but how is it possible to have 3 functions with the same name? 
> 
> It's okay.  They have 3 sets different argument litss: (char[]), (wchar[]), (dchar[]).
> 
>> how do i specify which one to use (it just wants to use the first one and i get a type mismatch compile error) Do i have to comment out the ones that i dont want to use?
> 
> No.  You shouldn't have to comment out anything in phobos.
> 
> I'm not sure what the problem is.  My blind guess is that you need to use a cast:
> 
> toUTF8(cast(wchar[]) "your string")
> or
> toUTF8(cast(wchar[]) str)
> 
> (By the way, it does help if you include a snippet of code.  Sometimes, the solution is obvious if we see it.)
> 
>>
>> sorry if im being a pain
> 
> Don't worry about it.  We've all starting programming in D fairly recently. :)
> 
> 
> Justin

Walter wrote:

> It picks one based on the type of the argument you supply to it.
>

wow, now these are features i like! Thanks for the help guys.