Welcome to Dream.In.Code
Become a Java Expert!

Join 150,375 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,689 people online right now. Registration is fast and FREE... Join Now!




API Class that does Escape character replacement

 
Reply to this topicStart new topic

API Class that does Escape character replacement, Adding java escape character functionality to my program.

NickDMax
13 Feb, 2008 - 11:48 AM
Post #1

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,871



Thanked: 53 times
Dream Kudos: 550
My Contributions
Before I go and write my own FSM I was wondering if anyone knew what class might be used to convert those neat little escape sequences like \n and \245 in strings.

I did have a neat little function that took care of \n and \t, but then the customer began to talk and I realized that I needed something more. Extending my little program does not work well since it just used the String.Replace function with a fancy little RegEx (?<=^|[^\\])\\[n].

But this method has a lot of problems when you try to do more complex replacements.

I searched/am searching the java API but so far no luck.

So, does anyone know a class that does these replacements?

User is offlineProfile CardPM
+Quote Post

skaoth
RE: API Class That Does Escape Character Replacement
13 Feb, 2008 - 04:33 PM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 357



Thanked: 12 times
Dream Kudos: 100
My Contributions
I generally write my own but this might be of interest
http://www.exampledepot.com/egs/java.util.regex/Escape.html
User is online!Profile CardPM
+Quote Post

NickDMax
RE: API Class That Does Escape Character Replacement
13 Feb, 2008 - 07:08 PM
Post #3

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,871



Thanked: 53 times
Dream Kudos: 550
My Contributions
That was not exactly what I had in mind. In the end I think I will just write my own. Of course, as soon as I am done someone will point out a simple 1 line bit of code that does it... oh well.
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: API Class That Does Escape Character Replacement
15 Feb, 2008 - 08:30 AM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,871



Thanked: 53 times
Dream Kudos: 550
My Contributions
Since I never found an API class for this I went ahead and did my own. For my application I have a version that just takes in a String and does the replacements, but I went the extra step of creating a FilterOutputStream version that I have posted as a snippet.

I figure that this might be helpful to someone. If nothing else it is an example of a Finite State Machine -- although not a terribly interesting one.

here it is.

Note: I am not too sure this works correctly with the whole unicode character bit.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:55PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month