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
1
vote
1 answer
How to extract Text Before and After NSRange
I am applying a search in a large content.Using NSRange to achieve this.
range = [textToSearch rangeOfString:searchText options:NSCaseInsensitiveSearch];
and then I am checking the presence of String like this:
if(range.location != NSNotFound){
…

Rahul
- 5,594
- 7
- 38
- 92
1
vote
1 answer
Removing an Attribute of NSTextView Text Selection
I have an NSTextView object that has been added through interface builder. I am able to change the background color of the text segment that has been selected as follows.
- (void)emphasizeText {
NSColor *c = [colorWell.color…

El Tomato
- 6,479
- 6
- 46
- 75
1
vote
2 answers
What's the best way to cut Swift string into 2-letter-strings?
I need to split a string into 2-letter pieces. Like “friend" -> "fr" "ie" "nd". (Okay, its a step for me to change HEX string to Uint8 Array)
My code is
for i=0; i

Desmond
- 767
- 1
- 6
- 18
1
vote
1 answer
Remove data from beginning of NSData object
I am assembling a NSData object and I am getting the following
0100020000
This is what I want except for the leading zero. I need it to be
100020000
I tried the following code. But it leaves me with 00020000.
NSRange range = NSMakeRange(0,…

Brian Kalski
- 897
- 9
- 35
1
vote
2 answers
How to create an immutable NSAttributedString with a ranged attribute
How can I initialize an NSAttributedString with a ranged attribute?
As it stands, I can only work out how to add a ranged attribute after initialization, which obviously doesn't work for immutable NSAttributedString instances.
If I have an…

Daniel Wagner-Hall
- 2,446
- 1
- 20
- 18
1
vote
0 answers
NSUnderlineStyleSingle underlines more than range of the text
I have implemented underline of mutableattributedtext, have set the range also correctly, but it still underlines more than the range specified and instead fills the text box it is contained in.
[attributedString…

anamika41
- 161
- 7
1
vote
1 answer
Can't catch range out of bounds exception in Objective-c
I'm getting this error message in xCode:
-[__NSCFString substringWithRange:]: Range {18446744073709551615, 1} out of bounds; string length 71. This will become an exception for apps linked after 10.10 and iOS 8. Warning shown once per app…

user714171
- 363
- 1
- 3
- 12
1
vote
2 answers
How can I pull the year out of this NSString?
I have a number of NSStrings of movie titles like this:
@"Accepted (2006)"
@"Blade Runner (1982)"
@"(500) Days of Summer (2009)"
@"RoboCop (1987) - Criterion #23"
I am trying to get the four-digit numeric-only year that is always between ( and )…

Ethan Allen
- 14,425
- 24
- 101
- 194
1
vote
0 answers
Manually add NSRange to NSMutableIndexSet?
I have been trying to add NSRanges to an NSMutableIndexSet (for later enumeration) however I think I am misunderstanding what addIndexesinRange does. At an early point I NSMakeRange "x" number of ranges that I create from a previous NSIndexSet.…

devone
- 293
- 3
- 10
1
vote
1 answer
Extract string from string with ranges inbetween special characters
I have a path, that I am retrieving in the form of a string. I would like to segregate the string into two different segments, but the method I am using gives me erroneous objects in the array.
Lets say I have path :
/Country/State/
I am…

Jteve Sobs
- 244
- 1
- 14
1
vote
0 answers
Swift : Is it possible to set TextView limit depending on TextView width and height
I have a textview and I set a text limit. Now I need a different way to set text limit. This textview height and width will change for every iPhone model. I want to set the limit as textview width and height. How can I do this ?
My code:
func…

jorjj
- 85
- 2
- 12
1
vote
1 answer
localizedCaseInsensitiveContainsString for iOS 7
How can i use localizedCaseInsensitiveContainsString for iOS 7?
Because ragneOfString method does not give me expected result. But localizedCaseInsensitiveContainsString method gives me desired result.
And localizedCaseInsensitiveContainsString is…

Sourabh Sharma
- 8,222
- 5
- 68
- 78
1
vote
0 answers
How do I only replace the first instance of a number in a string?
I am taking a description of the weather using rainfall in millimeters and converting it to inches. I have worked out to calculate the rainfall in inches and replace it in the string. Because the description also has other numbers, I want to only…

btechdog
- 15
- 6
1
vote
3 answers
How do I get the NSRange values of all the words of a UITextView in an array?
I need to highlight words in my UITextView one by one. How do I get the NSRange values of all the words of a UITextView and store them in an NSArray?

enigma
- 865
- 9
- 22
1
vote
3 answers
Convert NSRange in Objective-C to Swift
How do I convert this to Swift:
NSString *searchString = [NSString stringWithFormat:@"%@", @"Apple_HFS "];
NSRange range = [tempString rangeOfString:searchString];
NSUInteger *idx = range.location + range.length;
Thanks

jbrown94305
- 185
- 2
- 11