473,320 Members | 1,868 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

UTF8 Question

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).T oLower();
MessageBox.Show("keep-alive - "+strTemp+" - test");
if(Encoding.UTF8.GetString(connectionBytes).ToLowe r().Equals("keep-alive"))keepAlive=true;
else keepAlive=false;

Nov 30 '05 #1
2 1035
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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 30 '05 #2
Thanks for the reply.
I solved the problem with a Substring(0,10) comparision.

Mattias Sjögren wrote:
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

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


Nov 30 '05 #3

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

Similar topics

2
by: Chris Lacey | last post by:
Is anyone aware why the following code (intended to write XML into a memory-based XmlTextWriter, and return the complete document as a string) produces badly formed XML due to the resultant string...
1
by: Paul | last post by:
Assume you have two varchar (or Text) columns named L and U which are identical except that the charset for L is latin1 and the charset for U is utf8. All the records in L and U are identical in...
4
by: H Lee | last post by:
Hi, I'm an XML newbie, and not sure if this is the appropriate newsgroup to post my question, so feel free to suggest other newgroups where I should post this message if this is the case. I'm...
12
by: chunhui_true | last post by:
i have a class, it can read one line(\r\n ended) from string,when i read line from utf8 string i can't get any thing! maybe i should conversion utf8 to ascii??there is any function can conversion...
4
by: chris_fieldhouse | last post by:
Hi, I'm almost done with a php driven email filter and automated forwarder, I've tested it out with various emails and ironed out plain text and html. But this final item has me stumped. ...
4
by: uday.sen | last post by:
Hi, I need to convert a string from UTF8 to wide character (wchar_t *). I perform the same in windows using: MultiByteToWideChar(CP_UTF8, 0, pInput, -1, pOutput, nLen); However, in linux...
4
by: EmeraldShield | last post by:
(Dot Net 2 C# application - using Encoding.UTF8 with a StreamReader) I have a very strange problem that I cannot explain with a UTF8 Readline() although this could exist in other types of encoding,...
7
by: amygdala | last post by:
Hi, I'm trying to let PHP write a 'sitemap.xml' sitemap for Google and other searchengines. It's working, except that the content in the XML file doesn't seem to be UTF8. (Which it should be,...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
7
by: firepol | last post by:
Hello there, I am dealing with files encoded in UTF8 and I can't find a way to convert them into ANSI. I've already searched in google for this since a while, and I'm not achieving the result I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.