From owner-freebsd-java@FreeBSD.ORG Wed May 21 10:02:28 2003 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 35A3B37B42A for ; Wed, 21 May 2003 10:02:28 -0700 (PDT) Received: from axl.seasidesoftware.co.za (axl.seasidesoftware.co.za [196.31.7.201]) by mx1.FreeBSD.org (Postfix) with ESMTP id F0C1443FA3 for ; Wed, 21 May 2003 10:02:26 -0700 (PDT) (envelope-from sheldonh@starjuice.net) Received: from sheldonh by axl.seasidesoftware.co.za with local (Exim 4.20) id 19IWyu-00052G-Fq for freebsd-java@freebsd.org; Wed, 21 May 2003 19:02:24 +0200 Date: Wed, 21 May 2003 19:02:24 +0200 From: Sheldon Hearn To: freebsd-java@freebsd.org Message-ID: <20030521170224.GO3823@starjuice.net> Mail-Followup-To: freebsd-java@freebsd.org References: <20030521152846.GA16534@dyn107-dh.nbw.tue.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030521152846.GA16534@dyn107-dh.nbw.tue.nl> User-Agent: Mutt/1.5.4i Sender: Sheldon Hearn Subject: Re: String.replaceAll ' to \' X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 May 2003 17:02:28 -0000 On (2003/05/21 17:28), Rene Ladan wrote: > does anybody know how to convert a string with String.replaceAll, > replacing all ' with \' occurences? > > or should I just use a loop? String input = "What's the story's story?"; String output = input.replaceAll("'", "\\\\'"); I used the following class to test this: public class TestReplaceAll { public static void main(String[] args) { String input = ""; String regex = ""; String replacement = ""; try { input = args[0]; regex = args[1]; replacement = args[2]; } catch (ArrayIndexOutOfBoundsException e) { System.out.println( "usage: java TestReplaceAll input regex replace"); System.exit(1); } String output = input.replaceAll(regex, replacement); System.out.println(output); System.exit(output.equals(input) ? 1 : 0); } } I'd imagine this has more to do with The Java Language spec's take on literal string specification than it has to do with the specifics of String.replaceAll(). Ciao, Sheldon.