Want to get index of the last occurrence of # but bellow code working fine for the other character but not giving perfect result for particularity "#"
Code Working fine in viewDidLoad but not working in textfield shouldChangeCharactersInRange.
Code:
txtTest.text = @"@ashish @test #vijay $4030 @post";
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSRange range = [textField.text rangeOfString:@"a" options:NSBackwardsSearch];
NSLog(@"a :: %d ",range.location);
range = [str rangeOfString:@"@" options:NSBackwardsSearch];
NSLog(@"@ :: %d ",range.location);
range = [str rangeOfString:@"#" options:NSBackwardsSearch];
NSLog(@"# :: %d",range.location);
range = [str rangeOfString:@"$" options:NSBackwardsSearch];
NSLog(@"$ :: %d\n",range.location);
}
Result :: a :: 17 @ :: 26 # :: 2147483647 $ :: 20
NSNotFound
. Maybe the characters looks the same but are not, or there is a zero-width space in there or some such?@"#"
string. Use the arrow keys to move the cursor across it and you'll see it.