Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing using Java" Watch "Parsing using Java" New topic
Author

Parsing using Java

Jack Parrot
Greenhorn

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Parsing using Java
 
Similar Threads
string contains a TAB will not be recognized in drawString(String str,int x, int y) method
navigating JTextFields via up/down keys
FtpClient
display
Enums (Is this the best way)?