ios UTF8 encoding from nsstring

后端 未结 5 1573
小鲜肉
小鲜肉 2020-12-09 19:39

I am receiving a nsstring that is not properly encoded like \"mystring%201, where must be \"mystring 1\". How could I replace all characters that could be interpreted as UTF

相关标签:
5条回答
  • 2020-12-09 20:27
    lblDate.text=[NSString stringWithCString:[[arrTripDetail valueForKey:Param_vCurrencySymbol] UTF8String] encoding:NSUTF8StringEncoding];
    

    U can Convert & get Custom Emoji to string

    eg :

    input : \U20b9

    Output: ₹

    0 讨论(0)
  • 2020-12-09 20:31

    - (NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)encoding is what you want. basically use it like so:

    newString = [myString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    0 讨论(0)
  • 2020-12-09 20:34

    Do you want just percent encoding/decoding or full URL encoding/decoding? -(NSString*)stringByReplacingPercentEscapesUsingEncoding: will work if it is just percent encoding, but if there is full URL encoding there (so, for example a space could be either %20 or +) then you'll need something like the url decoding in the three20 library (or search on there, there are lots of examples of how to do it such as URL decoding/encoding NSString).

    0 讨论(0)
  • 2020-12-09 20:36

    Check the Strings and Non-ASCII Characters section of Formatting String Objects:

    NSString *s = [NSString stringWithUTF8String:"Long \xe2\x80\x94   dash"];
    
    0 讨论(0)
  • 2020-12-09 20:42
    [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
    
    0 讨论(0)
提交回复
热议问题