nsstring

String from NSInputStream is not valid utf8. How to convert to utf8 more 'lossy'

吃可爱长大的小学妹 提交于 2021-02-11 06:31:52
问题 I have an App that reads data from a server. Now and then, the data appears to be not valid UTF-8. If I convert from the byte array to an UTF8-String, the string appears nil. There must be some invalid not-UTF8 character in the byte array. Is there a way to 'lossy' convert the byte array to UTF8 and filter out only the invalid characters? Any ideas? My code looks like this: - (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent { switch (streamEvent){ case

Increasing Length of NSData

强颜欢笑 提交于 2021-02-07 19:54:46
问题 Basically, I have an NSString of 46 characters which i convert to NSData. I need to pad the string to 48 characters. It does not work via just adding ' ' to the end of the NSString. So, i just increased the length of NSData using this: NSString *string = @"__46characterlongstring__"; NSData *d = [string dataUsingEncoding:NSUTF8StringEncoding]; NSLog(@"d: %@", d); NSData *data = [NSData dataWithBytes:[d bytes] length:48]; NSLog(@"data: %@", data); The NSData called 'd' returns <723d6c67

How do I remove/decode URL percent encoding?

不问归期 提交于 2021-02-04 14:28:06
问题 I want to take a url and convert it to a more readable format. For example I have the following link: http://en.wikipedia.org/wiki/S%C3%A1ndor_Font I take away the unnecessary parts and am left with "S%C3%A1ndor_Font" as a NSString . Is there any sort of way to convert this into "Sándor Font" (what it actually should be), without having to type out every single combination of special characters and replacing each part of the string? To demonstrate how I want to use this, I wrote the following

How to change nsstring to nsdate format in iphone?

半腔热情 提交于 2021-01-28 01:04:06
问题 I have struggling with to convert nsstring to nsdate format. I have a date in nsstring format like (2011-08-25 18:30:00 +0000), but i want to change it in nsdate format (08/26/2011). How to change it? Can any one help me please? Thanks in advance... I have spend one day to solve this but i cant find out the solution.. Please help me friends.... This is my code, NSString *dateString = @"2011-08-25 18:30:00 +0000"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter

Convert String to double when comma is used

别来无恙 提交于 2021-01-27 08:02:01
问题 I have a UITextfield and it is being populated by data from database. The value is formatted in a way that the fractional part is separated by comma. So, the Structure is something like 1,250.50 I save the data in a string and when I try to use the doubleValue method to convert the string to a double or floating number. I am getting 1. Here is my code. NSString *price = self.priceField.text; //here price = 1,250.50 double priceInDouble = [price doubleValue]; Here I get 1 instead of 1250.50. I

Convert String to double when comma is used

老子叫甜甜 提交于 2021-01-27 07:59:09
问题 I have a UITextfield and it is being populated by data from database. The value is formatted in a way that the fractional part is separated by comma. So, the Structure is something like 1,250.50 I save the data in a string and when I try to use the doubleValue method to convert the string to a double or floating number. I am getting 1. Here is my code. NSString *price = self.priceField.text; //here price = 1,250.50 double priceInDouble = [price doubleValue]; Here I get 1 instead of 1250.50. I

NSString: strip out <b></b> and make an attributed string with color for that segment?

风流意气都作罢 提交于 2021-01-02 06:13:49
问题 Say if I have a string: This is a < b >simple < /b > string. I need to get rid of the < b >, (sorry there is no space between b and angle bracket, for some reason the preview does not show it), also make the word 'simple' to be bold, my thought was: replace the angle brackets and br with empty space make the 'simple' segment to have attributes The problem is once the tags are removed, I still need to know the word's location, do I first remember the location of 'simple', after removal, the

NSString: strip out <b></b> and make an attributed string with color for that segment?

一个人想着一个人 提交于 2021-01-02 06:13:39
问题 Say if I have a string: This is a < b >simple < /b > string. I need to get rid of the < b >, (sorry there is no space between b and angle bracket, for some reason the preview does not show it), also make the word 'simple' to be bold, my thought was: replace the angle brackets and br with empty space make the 'simple' segment to have attributes The problem is once the tags are removed, I still need to know the word's location, do I first remember the location of 'simple', after removal, the

NSString: strip out <b></b> and make an attributed string with color for that segment?

痴心易碎 提交于 2021-01-02 06:13:12
问题 Say if I have a string: This is a < b >simple < /b > string. I need to get rid of the < b >, (sorry there is no space between b and angle bracket, for some reason the preview does not show it), also make the word 'simple' to be bold, my thought was: replace the angle brackets and br with empty space make the 'simple' segment to have attributes The problem is once the tags are removed, I still need to know the word's location, do I first remember the location of 'simple', after removal, the

Replacing Multiple Different Occurences with Multiple Different Replacements - Swift4.2

牧云@^-^@ 提交于 2020-12-21 04:03:54
问题 Trying to find the exact format for doing this. I have a textField user input, I want to take that input and find multiple occurrences and replace each unique occurrence with a different unique character respectively. i.e. : replace " example " with " 1328571 " This is my code I currently have (currently is just set up for a single replacement so it doesn't work), formatted in the way that might help to explain what I'm trying to accomplish: let monoText: String = textInput.text! let