473,471 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ToString Help

Hi i have a fonction who check word in dictionnaire but when i use ToString he convert my word of 4 char in a string of 13 char ? Why

string[] dic; // Dictionnairy in memory

public void isDic(char[] aWord)

{

Array.Sort(aWord);

for(int i=0;i<dic.Length;i++)

{

if(aWord.Length == dic[i].Length)

{

char[] cWord = dic[i].ToCharArray();

Array.Sort(cWord);

if(aWord.ToString().CompareTo(cWord.ToString())==0 )

{

lOut.Text += dic[i] + " ";

}

}

}

lOut.Text += " FIN";

}

Thanks Max

Nov 15 '05 #1
4 1229
Maxime <ma*************@sympatico.ca> wrote:
Hi i have a fonction who check word in dictionnaire but when i use
ToString he convert my word of 4 char in a string of 13 char ? Why


char[].ToString() doesn't do what you think it does. Use

new String(char[]) to convert an array of characters into a string.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Hi, thanks Jon it's work
but there is it a way to compare a char[] to a char[] ?

thanks
Max

"Jon Skeet [C# MVP]" <sk***@pobox.com> a écrit dans le message de news:MP************************@msnews.microsoft.c om...
Maxime <ma*************@sympatico.ca> wrote:
Hi i have a fonction who check word in dictionnaire but when i use
ToString he convert my word of 4 char in a string of 13 char ? Why


char[].ToString() doesn't do what you think it does. Use

new String(char[]) to convert an array of characters into a string.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Maxime <ma*************@sympatico.ca> wrote:
Hi, thanks Jon it's work
but there is it a way to compare a char[] to a char[] ?


Well, this springs to mind:

static bool CharArraysEqual (char[] x, char[] y)
{
if (x.Length != y.Length)
{
return false;
}
for (int i=0; i < x.Length; i++)
{
if (x[i] != y[i])
{
return false;
}
}
return true;
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Thanks alot!

"Jon Skeet [C# MVP]" <sk***@pobox.com> a écrit dans le message de news:MP************************@msnews.microsoft.c om...
Maxime <ma*************@sympatico.ca> wrote:
Hi, thanks Jon it's work
but there is it a way to compare a char[] to a char[] ?


Well, this springs to mind:

static bool CharArraysEqual (char[] x, char[] y)
{
if (x.Length != y.Length)
{
return false;
}
for (int i=0; i < x.Length; i++)
{
if (x[i] != y[i])
{
return false;
}
}
return true;
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Ying Yang | last post by:
Hi, <code snippet> char* Car::toString() { //Example char* str = {""}; return str; }
2
by: Suresh | last post by:
Hi, I need to add a custom ToString method on an Enum Property. The default ToString method expands the whole name. But, I want only an short associated code with the long name of the enum type....
7
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
3
by: Mark Kamoski | last post by:
Hi-- What is the difference between Convert.ToString(obj) and CType(obj, String)? (Assume obj is a variable of type Object.) Please advise. Thank you.
6
by: Joe | last post by:
Stupid question, but I'm really stuck I have a class that overrides ToString(). When this class is cast back to Object, and ToString() called, Object.ToString() is called instead. I've tried...
8
by: John Cobb | last post by:
Excuse me if I use some terminology incorrectly as I am not well versed in Object Orientation. In short I want to create an Enumerated type similar to the following Enum Monitor as Byte Small...
1
by: Vilem Sova | last post by:
I want to use a user-defined object in the 'Add' method to add items to a combo box. The help documentation says that if you use an object in the add method then the object's 'ToString' method is...
101
by: Sean | last post by:
Book I am reading says that Cstr() is best method for efficency and safety however it doesnt compare that method of the .ToString() method. Which is best. Thanks
2
by: archana | last post by:
Hi all, I am facing some wired problem while using above mention data type. What i am doing is i am writing DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" +...
5
by: =?Utf-8?B?RmFlc3NsZXIgR2lsbGVz?= | last post by:
Hello, I'm facing a strange problem. We have an Asp.net 2.0 Web Application and somehow the date format is changing from one client to another even if all the code is running server-side... ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.