2016-06-24 1 views

Répondre

1

Il suffit d'utiliser la méthode du partage de chaîne puis ajoutez # au début

0

utilisation String.split (#) pour diviser la chaîne en string [] puis append # à chaque chaîne après que

0

voir Rege pour plus d'informations - vous pouvez définir une expression régulière et analyser la chaîne que vous voulez

1

Cela devrait vous aider

String str = "#123#456#abc"; 
    String[] arr = str.split("#"); 

    for(int i=1;i< arr.length;i++){ 
    System.out.println("#" + arr[i]); 
    } 

Sortie

#123 
#456 
#abc 
1

Vous aurez besoin de partager votre String avec regex "#". J'ai écrit un exemple pour votre cas.

final String entry = "#123#456#abc"; 
    String[] tokens = entry.split("#"); 
    // Your tokens array will contain {"", "123", "456", "abc"} 

    // Filter out the empty values and add an '#' before the others 
    List<String> formattedTokens = new ArrayList<>(); 
    for (String token : tokens) { 
     if(token.length() > 0){ 
      formattedTokens.add(String.format("#%s", token)); 
     } 
    } 

    // Your formattedTokens list will contain {"#123", "#456", "#abc"}