Java tutorial
/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.aliuge.crawler.extractor.selector.action.string; import org.aliuge.crawler.extractor.selector.action.StringSelectorAction; import org.apache.commons.lang3.StringUtils; /** * @author * @date 2014911 * @desc actionStringSelector??? */ public class StringReplaceAction extends StringSelectorAction { private String searchString; private String replacement; public StringReplaceAction(String searchString, String replacement) { super(); this.searchString = searchString; this.replacement = replacement; } public String getSearchString() { return searchString; } public void setSearchString(String searchString) { this.searchString = searchString; } public String getReplacement() { return replacement; } public void setReplacement(String replacement) { this.replacement = replacement; } /** * ?????? */ @Override public String doAction(String content) { return StringUtils.replace(content, searchString, replacement); } public static void main(String[] args) { String string = "@#$%$FGDFGFGHS#@$$Y"; StringReplaceAction action = new StringReplaceAction("#", ","); System.out.println(action.doAction(string)); String url = "http://pic1.ajkimg.com/display/anjuke/f5bcb775b47570557790e86d9c7a23dd/820x615.jpg"; //http://pic1.ajkimg.com/display/inform/f5bcb775b47570557790e86d9c7a23dd/820x615.jpg StringReplaceAction action4 = new StringReplaceAction("anjuke", "inform"); System.out.println(action4.doAction(url)); //http://pic1.ajkimg.com/display/inform/f5bcb775b47570557790e86d9c7a23dd/820x615.jpg //http://pic1.ajkimg.com/inform/anjuke/f5bcb775b47570557790e86d9c7a23dd/820x615.jpg } }