Java tutorial
//package com.java2s; //License from project: Apache License import java.security.Principal; public class Main { /** * Notice that, * If we split the signature string with ", ", * a value (like "Google, Inc") may be broke up unexpectedly. * So we check "=" at the same time. * (AppXplore v2.5.0 makes a mistake, too.) * * An example from Google Pinyin Input: * CN=Unknown, OU="Google, Inc", O="Google, Inc", L=Mountain View, ST=CA, C=US */ public static String analyseSignature(Principal principal, String str_nl) { //The result of principal.toString() is like this "x, x, x"; StringBuilder stringBuilder = new StringBuilder(principal.toString().replaceAll(", ", str_nl)); int index1 = 0; int index2; while (index1 >= 0) { if ((index2 = stringBuilder.indexOf(str_nl, index1)) < 0) { break; } if (!stringBuilder.substring(index1, index2).contains("=")) { stringBuilder.replace(index1 - str_nl.length(), index1, ", "); } index1 = stringBuilder.indexOf(str_nl, index1) + str_nl.length(); } return stringBuilder.toString(); } }