Removing BOM characters from AJAX-posted string
文章推薦指數: 80 %
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
CreatingacommaseparatedlistfromIList
延伸文章資訊
- 1doesn't remove unicode BOM from empty file - Lightrun
Prettier 1.18.2 No playground. For example using CLI : prettier --write test.js. Input: Empty fil...
- 2Node.js去除文字檔案BOM頭
Node.js去除文字檔案BOM頭 · BOM · BOM新增 · BOM移除 · 參考.
- 3remove utf8 bom javascript-掘金
remove utf8 bom javascript技术、学习、经验文章掘金开发者社区搜索结果。掘金是一个帮助开发者成长的社区,remove utf8 bom javascript技术文章由稀土...
- 4Bom | npm.io
strip-bom, remove-bom-buffer, remove-bom-stream, strip-bom-stream, ... Creates CycloneDX Software...
- 5How to properly handle UTF-8 BOM files in Nodejs?
Tagged with node, nodejstip, javascript. ... This happens because 𝗡𝗼𝗱𝗲𝗷𝘀 does not strip 𝗕𝗢𝗠 when ...