如何在 iPhone 应用程序中显示搜索表中的第一个单词

发布于 2024-12-04 00:01:20 字数 475 浏览 4 评论 0原文

嗨,我的 iPhone 应用程序中的每个应用程序都有一个搜索屏幕和一个搜索屏幕。我在搜索栏中有一些条目,例如 sudha、tharanga 和 Womensera(一些杂志),假设如果我们搜索板球特别版,它必须显示相应的杂志,

因此我计划使用如下所示的表格视图数据

sudha  (cricket special, anna hazare special)
tharanga  (footbal special,x special)
womens era (some y special)

,并将数据加载到表视图通过修剪括号 ( ) 之间存在的所有数据,我应该在表视图中显示剩余的数据

,那么我如何修剪字符串,以便它应该删除括号和括号符号中的数据

,以便我的表视图数据应该变成这样

sudha  
tharanga 
womens era 

,提前谢谢

hii every one in my iphone app i have a search screen & i have some entries in the search bar like sudha, tharanga and womens era (some magazines ) suppose if we search cricket special, it has to show the respective magazine

so i planned to have the table view data like follows

sudha  (cricket special, anna hazare special)
tharanga  (footbal special,x special)
womens era (some y special)

and while loading data to the table view by trimming the all data which is present between the brackets ( ) and should i display remaining in the table view

so how can i trim the string in such a way that it should remove the data with in brackets and bracket symbols

so that my table view data should become like this

sudha  
tharanga 
womens era 

, thanx in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热血少△年 2024-12-11 00:01:20

关于根据您的要求修剪字符串,我想最简单的方法是使用 - (NSArray *)componentsSeparatedByString:(NSString *)separator 方法,如下所示;

NSArray *anArray = [theFullString componentsSeparatedByString:@"("];

假设 theFullString = @"womensera (some yspecial)",结果数组的第一个元素将是 @"womensera "。我认为这工作正常。

Regarding trimming the string as per your requirement, I guess the simplest way to go about it is to use the - (NSArray *)componentsSeparatedByString:(NSString *)separator method as follows;

NSArray *anArray = [theFullString componentsSeparatedByString:@"("];

Assuming theFullString = @"womens era (some y special)", the resulting arrays first element would be as @"womens era ". I assume this works fine.

仙女山的月亮 2024-12-11 00:01:20

使用此 nnstring 方法获得所需的结果,

- (NSString *)substringWithRange:(NSRange)range; 

或者您可以这样做,首先找到括号位置,

int pointPos = -1;
for(int i=0; i<= [myString length]-1; i++){
    if ([myString characterAtIndex:i] == '(') {
        pointPos = i;
        break;
    }
}

NSString *finalString = [myString substringToIndex:pointPos];

Use this nnstring method to get the desired result,

- (NSString *)substringWithRange:(NSRange)range; 

OR you can do that, first find bracket location,

int pointPos = -1;
for(int i=0; i<= [myString length]-1; i++){
    if ([myString characterAtIndex:i] == '(') {
        pointPos = i;
        break;
    }
}

NSString *finalString = [myString substringToIndex:pointPos];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文