Here you can find the source of wildCardsToX(String s)
Parameter | Description |
---|---|
s | source string |
static public String wildCardsToX(String s)
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 ARM Ltd. and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w . j ava 2 s . c om*/ * ARM Ltd and ARM Germany GmbH - Initial API and implementation *******************************************************************************/ public class Main { /** * Replaces all '*' and '?' to 'x' and all non-alphanumeric chars to '_' in supplied string * @param s source string * @return the resulting string */ static public String wildCardsToX(String s) { if (s == null || s.isEmpty()) return s; StringBuilder res = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (Character.isLetterOrDigit(ch) || ch == '-' || ch == '.') { // allowed characters // do nothing } else if (ch == '*' || ch == '?') { // wildcards ch = 'x'; } else {// any other character ch = '_'; } res.append(ch); } return res.toString(); } }