The moose likes Java in General and the fly likes Parsing using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing using Java" Watch "Parsing using Java" New topic

Parsing using Java

Jack Parrot

Joined: Oct 29, 2009
Posts: 1
I have a string s that literally contains "This\tis\"my\"\tstring" that litterally contains all those characters including \t and \".

I am trying to figure out how to parse that string with the \t and \" and resolve them to their true meaning and then rebuild the string s so that it outputs:
This [tab] is[tab] "My"[tab] string.

[tab] cannot be displayed here but I am sure everyone knows that a tab is set of fixed number of spaces.

Can someone give me hint so i can have a direction to figure it out??? Thank you.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19869

No, not everyone knows that a tab is set of fixed number of spaces. Because it isn't. It's just a character. And often displaying it results in displaying a number of spaces instead. But not a fixed number of spaces. A lot of output displays have tab stops at (for example) every 4 positions, so a tab character will be represented by between 1 and 4 spaces. At other times displaying a tab character has no effect at all, as for example in HTML.

But anyway that's all irrelevant if your question is how to replace the pair of characters (backslash, 't') by a single tab character. You do that like this:

That's a hint, so I will leave the other half for you.
subject: Parsing using Java
jQuery in Action, 3rd edition