On 5/11/06, Jeff Mutonho <[EMAIL PROTECTED]> wrote:
> On 5/11/06, Java Mad <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > Does any one know how to replace all { with \{
> >
> > I tried String.replaceAll("{","\{") only to find exceptions since { is part
> > of the regular expression syntax stuff.
> >
> > What i want to achieve with this is to replace all {,(,[,] which is part of
> > a String with \{,\(,\[,\]
> >
> > e.g  "if()"
> > will be converted to if\(\)
> >
> > I need this for a Lexical Analyser
> >
> Try escaping the '{' with 2 backslashes
>

As in
String oldS="foo{";
System.out.println(oldS);
String newS= oldS.replaceAll("\\{","\\\\{");
System.out.println(newS);

will give you

foo{
foo\{




Jeff  Mutonho

GoogleTalk : ejbengine
Skype        : ejbengine
Registered Linux user number 366042

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CTJUG Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
-~----------~----~----~----~------~----~------~--~---

Reply via email to