A structure used to describe a portion of a series—such as characters in a string or objects in an NSArray object.
Questions tagged [nsrange]
343 questions
2
votes
3 answers
How can I compare case insensitive NSRange ?
I wrote a method to search for people in address book, and I want the method to be able to find "john bigs" even if I call the method [someAdressBook searchName:@"joh"];.
My method works for full names, but Im having issues in the partial names,…

JohnBigs
- 2,691
- 3
- 31
- 61
2
votes
1 answer
How to find the END_OF_LINE or WHITESPACE character in NSString
I am trying to parse a tweet that may contain a url. I want to format the url with a different color/font within the rest of the tweet. So obviously, the url can be placed anywhere in the text. So I have a category method that looks like this :…

unspokenblabber
- 1,567
- 1
- 11
- 19
2
votes
1 answer
iOS RangeOfString NSRegularExpressionSearch
i have a small problem, i am using one code snippet to remove html code from iOS string:
while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
s = [s stringByReplacingCharactersInRange:r…

ekussberg
- 559
- 1
- 8
- 19
1
vote
2 answers
ios nsrange char from end
Let's say I have:
this - is an - example - with some - dashes
NSRange will pick up the first instance of "-" with `rangeOfString:@"-" but what if I only want the last one?
I'm looking for something that works similar to lastIndexOf in JS. Thanks!

Jacksonkr
- 31,583
- 39
- 180
- 284
1
vote
3 answers
Terminating app due to uncaught exception 'NSRangeException' gives Range or index out of bounds'
I am working on barcode app and getting the location from CLController so its giving location,speed and many other thing so i substring that WithRange and getting exception so please kindly give me the reason and what should i do for this?
Thanks in…

Furqi
- 2,403
- 1
- 26
- 32
1
vote
3 answers
Objective-C: Substring and replace
I have a NSString which is a URL. This URL need to be cut:
NSString *myURL = @"http://www.test.com/folder/testfolder";
NSString *test = [myURL stringByReplacingCharactersInRange:[myURL rangeOfString:@"/" options:NSBackwardsSearch]…

Tim
- 13,228
- 36
- 108
- 159
1
vote
4 answers
Remove the vowels from a string
NSMutableString *stringa = [[NSMutableString alloc] initWithFormat:@"%@", surnameField.text];
if ([stringa length] < 3) {
[stringa appendString:@"x"];
}
NSMutableString *consonanti = [[NSMutableString alloc] init];
NSCharacterSet *vocali =…

Mario
- 17
- 1
- 7
1
vote
1 answer
Subtract multiple ranges from one range
How can we subtract multiple ranges of type Range from one range of type Range?
Example:
let str = "let <#name#> = <#value#>"
let range = str.startIndex..

Hassan Taleb
- 2,350
- 2
- 19
- 24
1
vote
1 answer
Get ranged string from text file without opening file with stringWithContentsOfFile
I'm trying read text from text file.
I used stringWithContentsOfFile to do this.
pathName = [[NSBundle mainBundle] pathForResource:sample ofType:@"txt"];
entireContent = [NSString stringWithContentsOfFile:pathName…

Daniel
- 15
- 3
1
vote
1 answer
Adding attribute to markdown NSAttributedString goes out of bounds
I have user input which can contain markdown or not. I want to show the user input on screen with rendered markdown. For some reason, I want to add my own static string which does not contain markdown to the end of the user input in the blue…

J. Doe
- 12,159
- 9
- 60
- 114
1
vote
1 answer
Getting ranges of duplicate substrings from string
I'm losing my mind over NSRange, RangeExpression and NSAttributedString functions. What I'm trying to achieve is to get all the ranges of a substring occurring in a text. What I ended up with is this:
let ranges: [NSRange] = textsToChange.compactMap…

aleksy.t
- 267
- 2
- 18
1
vote
0 answers
NSLog NSRange problem
I have a NSSting resultcontent that contains html data which is dynamic and length of html data is always different according to user input.
I could insert my html data in SQLite3 by replacing " from NSString. Now the problem is that SQlite3…

chits1
- 11
- 3
1
vote
2 answers
NSRange How to look for a space OR a return?
Possible Duplicate:
How to find and replace symbols in a string?
Sorry if the following is really obvious, but I'm just starting to work with NSRange and found the docs not really helpful with my question.
I have a string and I would like to look…

n.evermind
- 11,944
- 19
- 78
- 122
1
vote
1 answer
How to create a function when the user stops typing in swift
I have a Ui text field and when the user stops typing after about 1 second I want a check mark to appear. I have the following code:
@objc func getHintsFromTextField(textField: UITextField) {
print("Hints for textField: \(textField)")
…

coder123
- 247
- 3
- 17
1
vote
1 answer
ios - Replace/delete characters [• ] in UITextView on Enter
I have a UITextView with a custom NSTextStorage, where I add a list bullet, after each Enter, if the prior line starts with a list bullet.
When a user Enter and there is only a list bullet in the beginning of the line where the cursor is, I remove…

mahan
- 12,366
- 5
- 48
- 83