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
3
votes
2 answers
Add attributes to NSMutableAttributedString character by character
Here's my situation:
I have an NSMutableAttributedString with no attributes in a text view. Whenever the user presses the backspace key, I do not want a character to be deleted, I want it to be struck through, just like the "Track Changes" feature…

duci9y
- 4,128
- 3
- 26
- 42
3
votes
4 answers
Using enumerateObjectsAtIndexes or a for-loop to iterate through all indexes of an NSArray BEFORE a given index
What's the most concise way to iterate through the indexes of an NSArray that occur before a given index? For example:
NSArray *myArray = @[ @"animal" , @"vegetable" , @"mineral" , @"piano" ];
[myArray enumerateObjectsAtIndexes:@"all before index…

zakdances
- 22,285
- 32
- 102
- 173
3
votes
1 answer
NSRangeException when searching for bytes near end of NSData
I want to check the last 2 bytes of files in my app to make sure they are not corrupt .jpg's
rangeOfData:options:range: looks like a good option, but I am having a hard time figuring out how to get a proper NSRange. The range I am looking for is…

Slee
- 27,498
- 52
- 145
- 243
2
votes
3 answers
How do I use NSRange with this NSString?
I have the following NSString:
productID = @"com.sortitapps.themes.pink.book";
At the end, "book" can be anything.... "music", "movies", "games", etc.
I need to find the third period after the word pink so I can replace that last "book" word with…

Ethan Allen
- 14,425
- 24
- 101
- 194
2
votes
0 answers
iOS determine how much text fits into a frame
For laying out the text in a view, I would like to know
if it's possible to do the following:
given a string S, frame size and font size => return range (NSRange) of characters
that I can use to substring S, which of course will fit into the…

H.Rabiee
- 4,747
- 3
- 23
- 35
2
votes
2 answers
Objective-C Extract index of a range returned by rangeOfString:
How to extract an NSUInteger index from
NSRange range = [string rangeOfString: substring]
so I can write this index in [array objectAtIndex:index]?

wagashi
- 894
- 3
- 15
- 39
2
votes
3 answers
syntax of @selector
ok without using NSInvocation, let's say I have this code:
...
array = [NSMutableArray arrayWithObjects:@"Yoda", @"Jedi", @"Darth Vader", @"Darth Vader", @"Darth Vader" , @"Darth Vader", nil];
SEL removeObjectMessage =…

Dave Kliman
- 441
- 4
- 17
2
votes
1 answer
NSArray creating a subarray and then summing the values
I have some code that was originally written as:
+(double)averageOfArray:(NSArray*)array fromIndex:(int)from toIndex:(int)to{
if (to < 0) return 0;
if (to > array.count) return 0;
double sum = 0.0;
for (long i = from; i < to; i++){
…

Chase Roberts
- 9,082
- 13
- 73
- 131
2
votes
2 answers
How to get the range of the first line in a string?
I would like to change the formatting of the first line of text in an NSTextView (give it a different font size and weight to make it look like a headline). Therefore, I need the range of the first line. One way to go is this:
guard let…

Mischa
- 15,816
- 8
- 59
- 117
2
votes
1 answer
NSAttributedString: check if NSRange is valid
Given a NSRange and a NSAttributedString, what's the best way to verify that the range is valid, and won't exceed the bounds of the attributed string?
I am trying to do this:
[mutableAttributedString enumerateAttribute:NSFontAttributeName…

Z S
- 7,039
- 12
- 53
- 105
2
votes
1 answer
NSRange strange behavior
I have strange NSRange behavior on my device (iPhone iOS 4.3). This code has a different behavior on device and simulator.
for (Location *location in locationArray)
{
NSRange range1 = [location.name rangeOfString:searchText…

iPera
- 1,053
- 1
- 12
- 24
2
votes
1 answer
NSRange : incorrect behavior. Why?
range.location should be 0. Am i right ?
NSRange range;
range = [@"beer" rangeOfString:@"beer and vodka"];
if (range.location== NSNotFound)
{
NSLog(@"Why?");
}

Voloda2
- 12,359
- 18
- 80
- 130
2
votes
1 answer
How to find Multiple NSRange for a string from full string iOS swift
let fullString = "Hello world, there are \(string(07)) continents and \(string(195)) countries."
let range = [NSMakeRange(24,2), NSMakeRange(40,3)]
Need to find the NSRange for numbers in the entire full string and there is a possibility that both…

Karen
- 169
- 1
- 16
2
votes
2 answers
Can NSRange determine if a snippet of text exists in a larger string?
I have a large string coming back from an http GET and I'm trying to determine if it has a specific snippet of text or not (please forgive my sins here)
My question is this: Can / Should I use NSRange to determine if this snippet of text does…

Toran Billups
- 27,111
- 40
- 155
- 268
2
votes
1 answer
How to get the upperbound and lowerbound using NSRange in Objective-C?
I am having Swift code, need to get UpperBound and lowerBound. But in Objective C, I am not able to see the property or function for both Upper and lower Bound to get its value.
Snippet:
{
let upperBound = firstAppearance?.upperBound;
let…

Abilash Balasubramanian
- 968
- 8
- 22