2012-12-03 4 views
0

Je suis en train de scinder une chaîne en utilisant le code suivant dans mon application android.Mais son se écrasé.Quel est le problème ici.Il dit comme PatternSyntaxException.spliting Chaîne dans android

String quotes_string = "1.agshjdgasfghsfjhsdfhjsfhjgj.#**#2.dfjngdhfkgjkfglkhjkh.#**#3.fdghjkhdgkklf"; 
String[] apps = QuotesActivity.quotes_string.split("#**#"); 
String quote = apps[0]; 
txt_quotes.setText(quote); 

S'il vous plaît aidez-moi à résoudre ce.Merci à l'avance.

Répondre

2

Je pense que vous avez besoin d'échapper au caractère '*'. Changez la regex en "# \\ * \\ * #".

3

vous pouvez essayer en utilisant Split Motif:

String quotes_string = "1.agshjdgasfghsfjhsdfhjsfhjgj.#**#2. 
           dfjngdhfkgjkfglkhjkh.#**#3.fdghjkhdgkklf"; 

Pattern p = Pattern.compile("#\\*\\*#"); 

String[] apps =p.split(quotes_string); 

String quote = apps[0]; 
txt_quotes.setText(quote); 
1

Essayez comme ça

String quotes_string = "1.agshjdgasfghsfjhsdfhjsfhjgj.#**#2.dfjngdhfkgjkfglkhjkh.#**#3.fdghjkhdgkklf"; 

String[] apps = quotes_string.split("#\\*\\*#"); 
String quote = apps[0]; 
txt_quotes.setText(quote); 
0

Comme les docs Java dire à propos PatternSyntaxException here comme

exception non vérifiée lancée pour indiquer une erreur de syntaxe dans un motif d'expression régulière .

Vous pouvez utiliser PatternSplit suggéré comme ci-dessus