Click here to Skip to main content
15,919,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
for (int i = 0; i <=data.Length; i++)
           {

               if (data[i] == (byte)0)
                   return true;
           }


Above program works only for ascii encoding but in utf32 encoding its 32 bits so based on encoding format how to check a null byte
Posted
Updated 19-Jun-13 19:25pm
v2
Comments
Richard MacCutchan 20-Jun-13 3:35am    
Why are you casting the value zero to byte? Without the cast the compiler will coerce it to whataver size necessary based on the item size of your array.
yeshgowda 20-Jun-13 4:36am    
yes correct without typecasting also it works.but my question is i have to check a null byte in any of encoding formats? how to perform that
Richard MacCutchan 20-Jun-13 4:43am    
You should not be testing for null bytes, but null characters, and the character size will depend on the encoding: 8, 16 or 32 bits, or even variable length if it's UTF8.
yeshgowda 20-Jun-13 7:16am    
ok then i need to check whether string contains null character
Richard MacCutchan 20-Jun-13 7:34am    
That's what I said. Or are you still unclear about this issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900