Whats going on with this byte array? - Stack Overflow

文章推薦指數: 80 %
投票人數:10人

When that character gets encoded back to UTF-8, this results in the byte sequence EF BF BD . You cannot construct the original byte value from ... Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. LearnmoreaboutCollectives Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams Whatsgoingonwiththisbytearray? AskQuestion Asked 11years,3monthsago Modified 3monthsago Viewed 13ktimes 16 Ihaveabytearray: 0001000000128100000100C80000000000085C9F4FA50945D4CE ItisreadviaStreamReaderusingUTF8encoding //NoteIcan'tchangethiscode,tomanycomponentdependentonit. using(StreamReaderstreamReader= newStreamReader(responseStream,Encoding.UTF8,false)) { stringstreamData=streamReader.ReadToEnd(); if(requestData.Callback!=null) { requestData.Callback(response,streamData); } } WhenthatfunctionrunsIgetthefollowingreturnedtome(iconvertedtoabytearray) 000100000012EFBFBD00000100EFBFBD0000000000085CEFBFBD4FEFBFBD0945EFBFBD SomehowIneedtotakewhatsreturnedtomeandgetitbacktotherightencodingandtherightbytearray,butI'vetriedalot. Pleasebeaware,I'mworkingwithWP7limitedAPI. Hopefullyyouguyscanhelp. Thanks! Updateforhelp... ifIdothefollowingcode,it'salmostright,onlythingthatiswrongisthe5thtolastbytegetssplitout. byte[]writeBuf1=System.Text.Encoding.UTF8.GetBytes(data); stringbuf1string=System.Text.Encoding.BigEndianUnicode.GetString(writeBuf1,0,writeBuf1.Length); byte[]writeBuf=System.Text.Encoding.BigEndianUnicode.GetBytes(buf1string); windows-phone-7c#-4.0encodingbytearray Share Follow editedJul1,2011at4:57 John askedJul1,2011at4:22 JohnJohn 16511goldbadge11silverbadge55bronzebadges 7 Canyoushowusthecodethatiswriting/creatingthearray? – Emond Jul1,2011at4:30 Nope,it'scommingfromathirdpartyservice,that'stheexactdatathattheservicereturns...Besides,Ijustwanttogetitbacktowhatit'ssupposedtobe(asitstandsintheresponsestream) – John Jul1,2011at4:52 Iamseriouslyboggledonthisone... – John Jul1,2011at5:29 Thenhowdoyouknowinwhatencodingandbyte-orderthestreamiswrittento? – Emond Jul1,2011at5:29 Canyouattachanetworksniffer(Fiddler)toseewhatisactuallybeingtransmitted? – Emond Jul1,2011at5:31  |  Show2morecomments 1Answer 1 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 36 TheoriginalbytearrayisnotencodedasUTF-8.TheStreamReaderthereforereplaceseachinvalidbytewiththereplacementcharacterU+FFFD.WhenthatcharactergetsencodedbacktoUTF-8,thisresultsinthebytesequenceEFBFBD.Youcannotconstructtheoriginalbytevaluefromthestringbecausetheinformationiscompletelylost. Share Follow editedMay28,2021at14:59 StackzOfZtuff 2,06611goldbadge2626silverbadges2222bronzebadges answeredJul1,2011at6:05 RolandIlligRolandIllig 39.7k1010goldbadges8282silverbadges118118bronzebadges 5 That'swhatIwasafraidof...Sotheonlywaytoreallynotlosethedataisfigureoutwhattheencodingisandreadlikethat?Unfortunatly,forsomereasonIcan'tjustreadabytearray,theStreamrequiresastreamreadertoread... – John Jul1,2011at6:18 1 Yes,andwhenyouareindoubt,useISO-8859-1,soyouwillgetasimple1:1mappingfrombytestocharacters.Justforcuriosity:Whywouldanyonewanttoreadabytestreamlikethis(whichisobviouslynon-characterdata)asacharacterstream? – RolandIllig Jul1,2011at6:24 Can'tyouaskthesourceofthestreamforaspecification? – Emond Jul1,2011at6:52 Everythingis(andhasbeen)characterdataexceptforthisonenewpart.Eitherway,Ijustaddedsomeoverridestogettheactualbyte[]optionallyandallseemswellwiththeISO-8859-1encoding.Thanks! – John Jul1,2011at13:34 1 Wow,holyshit,sothesebytesareprettygoodmarkersofincorrectencodingbeingused! – mikenelson Dec14,2015at18:55 Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedwindows-phone-7c#-4.0encodingbytearrayoraskyourownquestion. TheOverflowBlog HowtoearnamillionreputationonStackOverflow:beofservicetoothers Therightwaytojobhop(Ep.495) FeaturedonMeta BookmarkshaveevolvedintoSaves Inboximprovements:markingnotificationsasread/unread,andafiltered... Revieweroverboard!Orarequesttoimprovetheonboardingguidancefornew... CollectivesUpdate:RecognizedMembers,Articles,andGitLab Shouldweburninatethe[script]tag? Linked 9 WeirdcharactersinURL 3 HandleHttpUploadZipfileinGolang 1 mysqllinebreaksformatting 1 Javaencoding-corruptedFrenchcharacters -2 LoadingPhototoLDAPViaMuleSoftJavamodule Related 966 ConvertInputStreamtobytearrayinJava 452 BestwaytoreadalargefileintoabytearrayinC#? 214 hexadecimalstringtobytearrayinpython 0 Storebinarydatastringintobytearrayusingc# 777 HowtoconvertabytearraytoahexstringinJava? 175 HowcanItransformstringtoUTF-8inC#? 888 ConvertingstringtobytearrayinC# 1 What'sthecorrectwaytocountthebytesneededforaUTF8conversion? HotNetworkQuestions StandardCoverflow-safearithmeticfunctions WhydidGodprohibitwearingofgarmentsofdifferentmaterialsinLeviticus19:19? CanIuseaspritesheetfromanexistingvideogameformypromotionalreel? DidMS-DOSeverdropabilitytosupportnon-IBMPCcompatiblemachines? MakeaCourtTranscriber Whatare"HollywoodTwin"beds? Howtoelegantlyimplementthisoneusefulobject-orientedfeatureinMathematica? Howdouncomputablenumbersrelatetouncomputablefunctions? Drawarrowfromequationtotextoutsideequation IsdocumentingabigprojectwithUMLDiagramsneeded,goodtohaveorevennotpossible? Howtotellifmybikehasanaluminumframe Howtosimplifyapurefunction? Changelinkcolorbasedinbackgroundcolor? Whatisthedefinitionofatrollinthelegalcontext? Alternativeversionsofbreathing? WhathappenswhenthequasarremnantsreachEarthin3millionyears? rename(Perl)-tryingtorenumberalistoffiles,startingatacertainvalue WhyareRussiancombatantsinUkraineconsideredsoldiersratherthanterrorists? StrangeFruitfromTomatoPlant Findanddeletepartiallyduplicatelines Whatisthebestwaytocalculatetruepasswordentropyforhumancreatedpasswords? Sciencefictionbook/novelaboutaliensinhumansbodies Whyare"eat"and"drink"differentwordsinlanguages? Doyoupayforthebreakfastinadvance? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-cs Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?