aspose file tools*
The moose likes Beginning Java and the fly likes Tracking Escape character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Tracking Escape character" Watch "Tracking Escape character" New topic
Author

Tracking Escape character

C Balajee
Greenhorn

Joined: Oct 18, 2000
Posts: 25
Hi,
I want to track the existence of '\' in my String variable i have written the following code but I'm not successful,
Looking forward to your help , the code is as follows.
========================================================

====================================================
If i change my input string to
"pankaj\\1234""
Then i'm able to track the '\'character.
I know this happens because we are escaping '\'
but in my application this string may come from an user input where i don't want to have any control over what my user is entering.
thanks for taking time to go through my code.
C.Balajee
[This message has been edited by Cindy Glass (edited September 25, 2001).]
Stefan Maric
Greenhorn

Joined: Sep 12, 2001
Posts: 8
Try using
int nIndex = 0;
String sText = "hell\o123\4";
String.indexOf('\', nIndex);
you can then adjust nIndex and repeat to find next occurrence
etc etc
C Balajee
Greenhorn

Joined: Oct 18, 2000
Posts: 25
Its giving me
"invalid escape sequence" error
when i try to run this snippet of code
Is there any other way...
Thanks again.
Bill Hause
Greenhorn

Joined: Jan 17, 2001
Posts: 13
As you pointed out, adding the second '\' "pankaj\\1234" fixes the problem because you are escaping the '\'.
Escaping is not necessary for user-entered strings. Therefore, you code should work as-is on strings entered by the user.
Try getting your string from a JOptionPane and your code should work as-is.
String text = JOptionPane.showInputDialog("Enter a String");

------------------

---------------------<BR>William D. Hause<BR>sphause@earthlink.net
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Tracking Escape character