NameError: global name ‘xrange’ is not defined in Python 3

I am getting an error when running a python program: Traceback (most recent call last): File “C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py”, line 110, in <module> File “C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py”, line 27, in __init__ File “C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\class\inventory.py”, line 17, in __init__ builtins.NameError: global name ‘xrange’ is not defined … Read more

How does String substring work in Swift

I’ve been updating some of my old code and answers with Swift 3 but when I got to Swift Strings and Indexing with substrings things got confusing. Specifically I was trying the following: let str = “Hello, playground” let prefixRange = str.startIndex..<str.startIndex.advancedBy(5) let prefix = str.substringWithRange(prefixRange) where the second line was giving me the following … Read more

How do I check if a string contains another string in Objective-C?

How can I check if a string (NSString) contains another smaller string? I was hoping for something like: NSString *string = @”hello bla bla”; NSLog(@”%d”,[string containsSubstring:@”hello”]); But the closest I could find was: if ([string rangeOfString:@”hello”] == 0) { NSLog(@”sub string doesnt exist”); } else { NSLog(@”exists”); } Anyway, is that the best way to … Read more