c# - casting a byte array stored in a string to a byte array -


i being passed byte array representing pdf part of xml node.

the byte array int xml looks

<document> xh0xqo+pgovvhlwzsavdawig4gcjawmdaxntc0mjkgmdawmdagbiakmdawmde1odq1nsawmdawmcbuiaowmdawmtu5mzy1idawmdawig4gcjawmdaxntk2mjegmdatg5myawmdawmcbuiaowmdawmtywmtqzidawmdawig4gcjawmmde2mdyznsawmdawmcbuiaowmdawmtywodk5idawmdawig4gcjawmdaxnntkgmdawmdagbiawmde2ndkxmiawmdawmcbuiaowmdawmty1mtwmdawig4gcjawmdaxnju0mzygmdawmde2ntuymyawmdawmcbuiaowmdawmty1nza5idawmdawig4gcjawmdaxnju5mjcgmdawmdagbiakmda4mtg3osawmdawmcbuiaowmmtgxotc4idawmdawig4gcnryywlszxikpdwvu2l6zsaxmtmxci9sb290idegmcbsci9jbmzvidmgmcbsci9jrcbbpdgymtqwqurdm0qwotrcrezbodi2mjm4q0vbm0yxoda3pia8odixndbbremzrda5nejerke4mjyymzhdruezrje4mdc+xqovrw5jcnlwdca0idagugo+pgpzdgfydhhyzwykmtgymdezciulru9gcg...........</document> 

so first copy bytearray string variable .

 string pdfbyte = getnodeusingxpath(xpath.....); 

now cast pdfbyte byte array.

 byte[] output = (byte[])pdfbyte;  byte[]  output = byte.parse(pdfbyte); 

these dont work.

i have looked online not find simple solution cast byte array stored in string variable byte array. pointers helpful.

basically, copy bytearray being sent part of xml byte array variable.

if you've got binary data within xml document, hope it's base64-encoded. text data , binary data different, , shouldn't trying store arbitrary binary data in string directly.

if is, can use:

string base64 = getnodeusingxpath(xpath.....);  byte[] output = convert.frombase64string(base64); 

you may find need trim string first:

byte[] output = convert.frombase64string(base64.trim()); 

if it's not base64, you'll need @ text looks like. may hex instead, although that's not terribly likely. if has use encoding.getstring(bytes) start with, code need fixed, , it's guaranteed lose data.

edit: can see of data, indeed it's base64.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -