File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tracking Escape character

 
C Balajee
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");

------------------
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic