Encode Emoji to string - Stack Overflow

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

128520 is the unicode scalar value of "😈": let text = "😈😀" let encoded = text.unicodeScalars.map { "" + String($0.value) + ";" }. Home Public Questions Tags Users Collectives ExploreCollectives FindaJob Jobs Companies Teams StackOverflowforTeams –Collaborateandshareknowledgewithaprivategroup. CreateafreeTeam WhatisTeams? Teams CreatefreeTeam CollectivesonStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore EncodeEmojitostring AskQuestion Asked 5years,4monthsago Active 4years,11monthsago Viewed 2ktimes 2 Iwanttoencodethisemoji😈tostring: Ihavetriedlikethis: letdata=self.comment.dataUsingEncoding(NSNonLossyASCIIStringEncoding,allowLossyConversion:true) ifletdata=data{ letemojiString=NSString(data:data,encoding:NSUTF8StringEncoding)as!String self.comment=emojiString } butitdoesn'twork. Iwanttoencodelike😈,not\ud83d\ude08 Sohowtodothis? iosswiftemoji Share Improvethisquestion Follow editedDec29'16at21:32 halfer 18.9k1616goldbadges8181silverbadges167167bronzebadges askedJul21'16at8:56 KhuongKhuong 10.2k1111goldbadges7171silverbadges107107bronzebadges Addacomment  |  1Answer 1 Active Oldest Votes 4 128520istheunicodescalarvalueof"😈": lettext="😈😀" letencoded=text.unicodeScalars.map{ ""+String($0.value)+";" }.joinWithSeparator("") print(encoded)//😈😀 Share Improvethisanswer Follow editedJul21'16at9:43 answeredJul21'16at9:03 MartinRMartinR 502k8282goldbadges11611161silverbadges12811281bronzebadges 3 Thishelpsme.Thanksalot@MartinR😈. – Khuong Jul21'16at9:09 itshouldbeletunicode=text.unicodeScalars.map({""+String($0.value)}).joinWithSeparator(",")togetexpectedstring:D – Duyen-Hoa Jul21'16at9:29 @Hoa:OPsaid:"Iwanttoencodelike😈"andthatisthesyntaxofXML"characterentities".Butanyway,itshouldbeeasytoadapttheexamplecodetotheconcreteneeds. – MartinR Jul21'16at9:41 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?Browseotherquestionstaggediosswiftemojioraskyourownquestion. TheOverflowBlog Podcast398:Feelinginsecureaboutcode’ssecurity Newdata:Whatdeveloperslookforinfuturejobopportunities FeaturedonMeta Reducingtheweightofourfooter NewresponsiveActivitypage Communityinputneeded:Therulesforcollectivesarticles Related 1754 HowcanImakeaUITextFieldmoveupwhenthekeyboardispresent-onstartingtoedit? 572 ConvertUTF-8encodedNSDatatoNSString 884 HowtocheckiOSversion? 1447 Passingdatabetweenviewcontrollers 252 ConvertbetweenUIImageandBase64string 473 Loading/DownloadingimagefromURLonSwift 740 Xcode6:Keyboarddoesnotshowupinsimulator 348 Swift-encodeURL 565 Whyareemojicharacterslike👩‍👩‍👧‍👦treatedsostrangelyinSwiftstrings? 7 SwiftEncode/decodeemojis HotNetworkQuestions WhyisthesnowlinehigherintheHimalayasthanontheequator? Howtomakewhippedcreamjustlikeinacanister? Aresomeprotonsmoremassivethanothersduetospinningatadifferentrateorbeinginamoreexcitedstate? Repetitionoforbitalstructureonmanyscales-whatisitcalled? Helpmefindthetitleofasci-fiapocalypticmoviefollowingabrother-sisterduo,butthesisterisdifferentsomehow Whyarealltrajectoriesinspaceaconicsections? AreILSapproachestaughtaspartofinstrumentrating? Isbioluminescencemetabolicallyexpensive? RemoveUnwantedshadowingwithLineIntegralConvolutionPlot Howismomentumconservedindiffraction? “Letforeach𝑖”vs.“Foreach𝑖let” Gasrangeclicksbutdoesnotignite Helpindeterminingthefeaturesofafictionalplanet Whataretheconsequencesofgettingapositivedrugresultwhenyourbagsareswabbedattheairport? Whatisthenameofthetoolthattheguyinthisvideoisusingtolevelupthemudonceiling? Howisthis.mp4file596523hourslong? Isitoktoshareapaperacceptedforpublicationwithasingleperson? Extremedropsinharddiskperformance HowclosearetopBridgeplayerstoperfectplay? Approximatesizeofthe"hut"objectobservedfromtheYutamoonrover? Helpwithtitleofbookaboutcatlikepeople Explanationsforthreecluesinacrypticcrossword CanIconverta1x9speedbicycletosinglespeedbyputting9identicalcogsintocassette? HowmuchdutywillIhavetopayimporting72bottlesofwinefromItalytoUK morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-swift Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?