Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2005

Tip: Looking for answers? Try searching our database.

UTF8 Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nuno Magalhaes - 30 Nov 2005 18:27 GMT
Why does (in the code below) the message should appear as "keep-alive -
keep-alive - test" but it only appears as "keep-alive - keep-alive".
That is why the last comparation (Equals) isn't getting true. Is it
from the "Convert.ToByte('\0')" that does the comparation false?
I'm shure that the strings are identical but it gives me false. Why?

Any help is appreciated, (Possible some UTF8 compatibility issues?)
Nuno Magalhaes.

Here's the code:
***************************************************************
byte[] connectionBytes=new byte[16];
for(int i1=index+12,i2=0;;i1++,i2++)
{
if(bytes[i1]=='\n')
{
connectionBytes[i2]=Convert.ToByte('\0');
break;
}
connectionBytes[i2]=bytes[i1];
}
string strTemp=Encoding.UTF8.GetString(connectionBytes).ToLower();
MessageBox.Show("keep-alive - "+strTemp+" - test");
if(Encoding.UTF8.GetString(connectionBytes).ToLower().Equals("keep-alive"))keepAlive=true;
else keepAlive=false;
Mattias Sjögren - 30 Nov 2005 20:03 GMT
>Why does (in the code below) the message should appear as "keep-alive -
>keep-alive - test" but it only appears as "keep-alive - keep-alive".

Because the MessageBox will only show the string up to the first '\0'
character.

>That is why the last comparation (Equals) isn't getting true. Is it
>from the "Convert.ToByte('\0')" that does the comparation false?

Yes one string will have a null character at the end but the literal
"keep-alive" doesn't.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nuno Magalhaes - 30 Nov 2005 21:03 GMT
Thanks for the reply.
I solved the problem with a Substring(0,10) comparision.

> >Why does (in the code below) the message should appear as "keep-alive -
> >keep-alive - test" but it only appears as "keep-alive - keep-alive".
[quoted text clipped - 14 lines]
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.