Removing BOM characters from AJAX-posted string

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

The characters are in the middle of strings I want to simply remove them all. The data comes from a JavaScript source, which I get from a ... 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 RemovingBOMcharactersfromAJAX-postedstring AskQuestion Asked 9years,11monthsago Modified 9years,11monthsago Viewed 6ktimes 1 MycontentcontainsmultipleBOM(EFBBBF)charactersandIwanttoremovethem.ThecharactersareinthemiddleofstringsIwanttosimplyremovethemall. ThedatacomesfromaJavaScriptsource,whichIgetfromaCKEditorinstance.ThenIPOSTthevariableandreaditasstringonmybackendandtheBOMSarethere.Fornow,theyarepersistedasis,butthisresultsinerrorsinpost-processingwhenthecharactersareinterpretedandstartshowingupmid-content.IsuspecttheycomefromsomethingthatwascopypastedintomyCKEditor. Icanstepthroughthestringcharbychar,butIdon'tknowhowtocompareagainsttheBOM.Woulditsomehowbepossibletocomparethehexvaluesofthestringbytesandcomparethreebytesequences? c#.netbyte-order-mark Share Follow askedOct23,2012at6:52 JoelPeltonenJoelPeltonen 12.5k55goldbadges6464silverbadges9898bronzebadges Addacomment  |  2Answers 2 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 8 Theutf-8BOMbytesgettranslatedto\ufeff.Unicodecharacter"Zerowidthno-breakspace",can'tseethem,can'thearthem.Filterthemoutwith: vargood=bad.Replace("\ufeff",""); Share Follow answeredOct23,2012at9:50 HansPassantHansPassant 906k143143goldbadges16551655silverbadges24832483bronzebadges 3 Greatsuccess!Onequestionthough,mightthiscauseproblemsbyremovingotherbytesthatgettranslatedintothesameunicodecharacter?IdoubtthatI'llmissanyiftheygetremovedbutarethereotherimportantorworth-mentioningsuchcharacters? – JoelPeltonen Oct23,2012at9:58 1 Youcan'tseethem,youcan'thearthem. – HansPassant Oct23,2012at10:15 Toreplaceanyocurenceinthestring,use:constgoodStr=badStr.split('\ufeff').join(''); – Harps Nov9,2021at9:33 Addacomment  |  0 Trythefollowing: CleanString=DirtyString.Replace("\u00EF\u00BB\u00BF",null); Share Follow answeredOct23,2012at7:06 PeterStockPeterStock 19177bronzebadges 2 ThewayItestedthiswastodostrings2=s.Replace(...)andthenDebug.WriteLine(s2);.ThenIcopy-pastedtheoutputfrommyoutputwindowtoNotepad++andswitchedtoviewHEX:IstillseetheBOM.DidItryitwrong? – JoelPeltonen Oct23,2012at7:26 That'showitisworkingforme.Maybeyoufindthishelpful. – PeterStock Oct23,2012at9:58 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?Browseotherquestionstaggedc#.netbyte-order-markoraskyourownquestion. TheOverflowBlog HowtoearnamillionreputationonStackOverflow:beofservicetoothers Therightwaytojobhop(Ep.495) FeaturedonMeta BookmarkshaveevolvedintoSaves Inboximprovements:markingnotificationsasread/unread,andafiltered... Revieweroverboard!Orarequesttoimprovetheonboardingguidancefornew... CollectivesUpdate:RecognizedMembers,Articles,andGitLab Shouldweburninatethe[script]tag? Visitchat Linked 72 CreateTextFileWithoutBOM 19 HowdoIignoretheUTF-8ByteOrderMarkerinStringcomparisons? Related 1012 CreatingacommaseparatedlistfromIListorIEnumerable 303 Mostefficientwaytoremovespecialcharactersfromstring 1123 Getpropertyvaluefromstringusingreflection 184 Removecharactersafterspecificcharacterinstring,thenremovesubstring? 732 HowdoIremoveallnonalphanumericcharactersfromastringexceptdash? 2 StripBOMfromageneratedstring(notafile) 0 removebomfromwebsite? 5 RemovingBOMfromgzip'edCSVinPython 1651 WhynotinheritfromList? HotNetworkQuestions Howtoremovetikznode? Adecimal-basedunitoftime Whenisthefirstelementintheargumentlistregardedasafunctionsymbolandwhennot? Whatisthebestwaytocalculatetruepasswordentropyforhumancreatedpasswords? Unsurewhatthesewatersoftenerdialsarefor DoestheDemocraticPartyofficiallysupportrepealingtheSecondAmendment? WhytheneedforaScienceOfficeronacargovessel? Traditionally,andcurrently,whatstopshumanvotecountersfromalteringballotstomakethem'Spoilt/Invalidvotes? WhathadEstherdonein"TheBellJar"bySylviaPlath? Isitokaytore-renderaplotusedinanotherpublication? Sciencefictionbook/novelaboutaliensinhumansbodies rename(Perl)-tryingtorenumberalistoffiles,startingatacertainvalue IfthedrowshadowbladeusesShadowSwordasarangedattack,doesitthrowasword(thatitthenhastoretrievebeforeusingitagain)? sshhowtoallowaverylimiteduserwithnohometologinwithpubkey UnderstandingElectricFieldsLinesandhowtheyshow‘like’chargesrepelling I2C(TWI)vsSPIEMInoiseresistance IsdocumentingabigprojectwithUMLDiagramsneeded,goodtohaveorevennotpossible? HowdothosewhoholdtoaliteralinterpretationofthefloodaccountrespondtothecriticismthatNoahbuildingthearkwouldbeunfeasible? Whatdoes"parameterizedby"mean? CanIuseaspritesheetfromanexistingvideogameformypromotionalreel? LaTeX2(e)vsLaTeX3 Whatisthedefinitionofatrollinthelegalcontext? DidMS-DOSeverdropabilitytosupportnon-IBMPCcompatiblemachines? Shouldselectedoptionsberemovedfromsingle-andmulti-selectdropdownlists? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-cs Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?