Get first 30 bytes from string c# -


how first 30 bytes string?

eg: string phone = "my name 绳図轉丰 blah blah"; then

function returned "my name" (30 bytes) help.

binaryformatter bf = new binaryformatter(); byte[] bytes; memorystream ms = new memorystream(); string orig = "喂 hello 谢谢 thank you"; bf.serialize(ms, orig); ms.seek(0, 0); bytes = ms.toarray(); messagebox.show("original bytes length: " + bytes.length.tostring()); messagebox.show("original string length: " + orig.length.tostring()); 

as others said, string not have byte representation depends on encoding used. can try this:

encoding.utf8.getbytes("your string interesting data").take(30); 

but have remember depending on selected encoding, values returned getbytes method may differ.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -