nsstring

Getting index of a character in NSString with offset & using substring in Objective-C

爷,独闯天下 提交于 2019-12-12 07:41:17
问题 I have a string! NSString *myString=[NSString stringWithFormat:@"This is my lovely string"]; What I want to do is: Assuming the first character in the string is at index 0. Go to the 11th character (That is 'l' in the above case), and find the position of first occurring space backwards (In the above string, the position of first occurring space if we go backwards from 'l' is at position 10). Let's call the index of this space 'leSpace' having value 10. Substring the remaining string to a new

how to remove characters from NSString after specific NSString

南笙酒味 提交于 2019-12-12 07:30:43
问题 I am having a string as follows NSString str1 = @"Hello your bal = 68094"; and I want to remove all characters after "=" symbol encounters in string. Can any one give me the solution for this? 回答1: Try the following solution: NSString *str1 = @"Hello your bal = 68094"; NSRange range = [str1 rangeOfString:@"="]; if (range.location != NSNotFound) { NSString *newString = [str1 substringToIndex:range.location]; NSLog(@"%@",newString); } else { NSLog(@"= is not found"); } or NSString *str1 = @

IOS : NSString retrieving a substring from a string

家住魔仙堡 提交于 2019-12-12 07:30:06
问题 Hey I am looking for a way to extract a string from another string. It could be any length and be in any part of the string so the usual methods don't work. For example http://bla.com/bla?id=%1234%&something=%888% What I want to extract is from id=% to the next %. Any idea's? 回答1: Use the rangeOfString method: NSRange range = [string rangeOfString:@"id=%"]; if (range.location != NSNotFound) { //range.location is start of substring //range.length is length of substring } You can then chop up

NSDate returning nil for the NSDateFormatter set correctly

时光怂恿深爱的人放手 提交于 2019-12-12 06:32:49
问题 I am getting the date in NSString format as mentioned below. Input:datestring = 30/04/2013 04:49 PM I am applying the format for NSDateformatter as mentioned below to convert this NSString to NSDate . Format:dateFormat= dd/MM/yyyy hh:mm a I still get the date conversion to Nil. Please help as I am not understanding this issue.Here is my code snippet to explain what i am doing in the utility function. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat

Set Title of UIButton from Selected Row of UIPickerView

此生再无相见时 提交于 2019-12-12 06:28:43
问题 Detailed scenario is like this : I am creating 10 buttons using a loop and setting the tags from 0-9. On tap of each button I am calling a UIPickerView in which I am loading data from different arrays. Till here I am getting the expected results. But I want the selected row from the pickerView should set as the title of respective button. Way I tried - I stored the selected row in a NSString in the pickerViewDelegate method and trying to setTitle like : [myButton setTitle:selectedString

Equal strings not equal? [duplicate]

北战南征 提交于 2019-12-12 06:24:32
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Understanding NSString comparison in Objective-C I'v encountered strange things in objective-c, I'm trying to compare cell.label with elements title which is string. to identify whever it is a cell I am looking for. NSLog(@"%@", cell.textLabel.text); NSLog(@"%@", [_dropDownSelection1.elements[1] title]); if(cell.textLabel.text == [_dropDownSelection1.elements[1] title]){ NSLog(@"Positive"); } else{ NSLog(@

How to fix encoding issues ? (NSString / XMLParsing)

淺唱寂寞╮ 提交于 2019-12-12 05:29:54
问题 I parsed an XML file containing UTF8/latin characters (é, â, è, î, etc...). At first I tried to fix this with a function replacing the wrong chars. But I'm having a problem with à , replaced by " . And as I don't want to replace all the " of my file, I have to find another way to fix it. Any idea to fix this ? Thanks a lot for your advices 回答1: To finally answer this question, it worked using TBXML. But only with UTF-8 encoding, not ISO-8859-1. 来源: https://stackoverflow.com/questions/10789547

How to convert a Swift enum: String into an Objective-C enum: NSString?

允我心安 提交于 2019-12-12 05:14:07
问题 I am having an issue converting this swift enum to Objective-C : public enum ISO8601Format: String { case Year = "yyyy" // 1997 case YearMonth = "yyyy-MM" // 1997-07 case Date = "yyyy-MM-dd" // 1997-07-16 case DateTime = "yyyy-MM-dd'T'HH:mmZ" // 1997-07-16T19:20+01:00 case DateTimeSec = "yyyy-MM-dd'T'HH:mm:ssZ" // 1997-07-16T19:20:30+01:00 case DateTimeMilliSec = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" // 1997-07-16T19:20:30.45+01:00 init(dateString:String) { switch dateString.characters.count { case 4:

Why the http post request body always wrapped by Optional text in the Swift app

删除回忆录丶 提交于 2019-12-12 05:12:45
问题 I am writing the swift code to send a http post request to the php server. But my php script always get the strange post body because the parameters are wrapped by the Option(), If I send parameters like "id=john&password=1234", the server will get Optional(id=john&password=1234). But this is not what I want because php cannot analyse the parameters in the normal way. I have no idea about what's going wrong here; var postString: String = "id=john&password=1111" request.HTTPBody = (postString

Problems with NSString inside viewWillDisappear

空扰寡人 提交于 2019-12-12 04:54:48
问题 I am battling with this piece of code for days now, I really would appreciate your insight. So here it is... fileName which is declared in my .h file as NSString *fileName; and later as @property (nonatomic, copy) NSString *fileName; is not accessible inside viewWillDisappear . It just shows up as nil object, or some weird value when I debug. When I debug, my console show this msg: Printing description of fileName: FileNumber1 When I reach to viewWillDisappear my console shows this: Printing