Searching NSString Problem
I have this problem:
I am using UIWebView to render a string. User selects a range of text which开发者_如何学编程 I can get By this code:
NSString *selection = [pageView stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString();"];
I am using this code to get the range of the selection within the original content:
NSRange range = [Content rangeOfString:selection];
The problem is the selection is not found in some cases, so I get range.length = 0,
When I compare both strings in TextEdit, I found them identical, but even textEdit can not find the selection string within the content.
Any hint to solve this problem is appreciated.
May this help someone to notice what is up:
Current language: auto; currently objective-c 2010-11-29 01:19:35.614 Asseera[729:207] select range is فندب النبىُّ صلى الله عليه وسلم أُمَّته إلى التسمى بأسمائهم 2010-11-29 01:19:58.073 Asseera[729:207] subContent is ولما كان الأنبياءُ ساداتِ بنى آدم، وأخلاقُهم أشرفَ الأخلاق، وأعمالُهم أَصَحَّ الأعمال، كانت أسماؤهم أشرفَ الأسماء، فندب النبىُّ صلى الله عليه وسلم أُمَّته إلى التسمى بأسمائهم، كما في سنن أبى داود والنسائى عنه: ((تَسَمَّوْا بأَسْمَاءِ الأنْبِيَاءِ)) ولو لم يكن في ذلك من المصالح إلا أن الاسمَ يُذَكِّرُ بمسمَّّاه، ويقتضى التعلُّقَ بمعناه، لكفي به مصلحةً مع ما في ذلك من حفظ أسماء الأنبياء وذِكرها، وأن لا تُنسى، وأن تُذكِّر أسماؤُهم بأوصافهم وأحوالهم. 2010-11-29 01:21:05.922 Asseera[729:207] selection range is {2147483647, 0}
Did you try to get some constant value? Like the document title instead of something that is user dependent. Maybe there is a issue with getSelection()
?
精彩评论