Java: Découper une chaîne de caractères(String) à l’aide d’un séparateur

Author:

 int,string,char,static, url, socket, url, socket, java
{filelink=23}

/**
 * @(#)ExempleSplit.java
 *  Découper une chaîne de caractères(String) à l'aide d'un séparateur
 * 
 * @author sakoba(mesexemples.com) 
 *sakoba(java.mesexemples.com) @version 1.00 2012/12/4
 */

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

public class ExempleSplit {

    public static void main (String[] args) 
    	{ 
    		String str = "Tu es cool";
			String str2 = "Foot, Ballon,Sport";
			// Découper les String en deux tokens
			String[] array1 = StringUtils.split( str, " ,", 2 );
			String[] array2 = StringUtils.split( str2, " ,", 2 );
			System.out.println( ArrayUtils.toString( array1 ) ); // {Tu,es cool}
		    System.out.println( ArrayUtils.toString( array2 ) ); // {Foot,Ballon,Sport}
        }
    
    
}

A Voir sur le même Sujet:

  • java decouper a chaque caratère
  • java couper à chaque caactère
  • découper une chaine java

Leave a Reply

Your email address will not be published. Required fields are marked *