2013-05-09 4 views
1

Voici une chaîneComment modifier cette chaîne

"Level1, Row 1, Gold, Seat no 7". "Level1, Row 1, Gold, Seat no 8". Name: Karan. 

Je suis en train de faire de cette chaîne comme ce

Level1, Row 1, Gold, Seat no 7, Level1, Row 1, Gold, Seat no 8, Name: Karan 

Je dois pas et le nom dans ce domaine et avant le siège de recherche que j'ai besoin pour séparer cela en tableau. C'est comme ça que j'essaie.

[outStr stringByReplacingOccurrencesOfString:@"." withString:@","]; 
//[outStr stringByReplacingOccurrencesOfString:@"\"" withString:@""]; 
NSLog(@"outstr:%@", outStr); 
NSArray *arrSplit1 = [outStr componentsSeparatedByString:@","]; 
NSString *stringToSearch = @"seat no"; 
NSString *stringToSearch1 = @"name"; 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",stringToSearch]; 
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"SELF contains[c] %@",stringToSearch1]; 
NSArray *results = [arrSplit1 filteredArrayUsingPredicate:predicate]; 
NSArray *results1 = [arrSplit1 filteredArrayUsingPredicate:predicate1]; 
NSLog(@"results:%@", results); 
NSLog(@"results:%@", results1); 

Comment puis-je atteindre ce guide s'il vous plaît.

+0

je pense que vous avez Ces trois cordes 1. "Niveau 1, Rangée 1, Or, Siège n ° 7" 2. "Niveau 1, Rangée 1, Or, Siège n ° 8" 3. "Nom: K aran ". Ai-je raison ? –

+0

@DharmbirChoudhary juste une chaîne obtenue à partir de la numérisation du ticket. C'est la chaîne complète que j'ai. –

+0

Je pense que vous avez obtenu votre réponse, donc besoin d'expaliner .. –

Répondre

1

essayer comme ça it'l donne une sortie correcte,

NSString *stringURL = @"Level1, Row 1, Gold, Seat no 7\". \"Level1, Row 1, Gold, Seat no 8\". Name: Karan."; 
    stringURL=[stringURL stringByReplacingOccurrencesOfString:@"\"" withString:@""]; 
    stringURL=[stringURL stringByReplacingOccurrencesOfString:@"." withString:@","]; 
    if([stringURL hasSuffix:@","]) 
     stringURL=[stringURL substringToIndex:[stringURL length]-1]; 
    NSLog(@"%@",stringURL); 

O/P: -

Level1, Row 1, Gold, Seat no 7, Level1, Row 1, Gold, Seat no 8, Name: Karan 

dans votre code avec \" remplacer "

+0

où remplacer. –

+0

@iPhone: en fonction de vos besoins, vous pouvez remplacer votre chaîne par une chaîne stringURL dans mon code. – Balu

0

Utilisez cette méthode de NSString.

- (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement