Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , ,

Sponsored Links


Replace backslash in a string

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 18-02-2010
Member
 
Join Date: Dec 2009
Posts: 296
Replace backslash in a string

Sponsored Links
Hello
I must insert in my database for a string containing the backslash \ and when reregistration in ABSE data s nothing displays.
So I try to do this:
Code:
Code:
myText.replaceAll("\\","\\\\");
Its returns me a syntax error, how to provide a basis to understand my backslash? Any help on this topic will interest me.

Reply With Quote
  #2  
Old 18-02-2010
Member
 
Join Date: Nov 2009
Posts: 356
Re: Replace backslash in a string

Hello,
If I am not wrong then you are getting the following error.
Code:
java.util.regex.PatternSyntaxException: 
Unexpected internal error near index 1
\
If you want to remove this error from getting when you compile the code, then you have to modify your code.
Reply With Quote
  #3  
Old 18-02-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: Replace backslash in a string

Hello,
Just in case you do this well in your code:
Code:
myText = myText.replaceAll("\\", "\\\\");
Because the method replaceAll returns the modified string, and does not alter that which is given as parameter. I hope you are getting the point what I am trying to explain you. If you want more information on this , then you can go to the sun's official site for java and there you can find more detailed information on this.
Reply With Quote
  #4  
Old 18-02-2010
Member
 
Join Date: Dec 2009
Posts: 192
Re: Replace backslash in a string

Hello,
Even I was trying a similar kind of a program , And even i get a same error , i have no idea what this error means. So, please if you have any idea then even i am the interested candidate.
Here is what I get
Code:
java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
 ^
at java.util.regex.Pattern.error(Unknown Source)
	at java.util.regex.Pattern.compiles(Unknown Source)
	at java.util.regex.Pattern. <init>(Unknown Source)
	at java.util.regex.Pattern.compiles(Unknown Source)
	at java.lang.String.replaceAll(Unknown Source)
Reply With Quote
  #5  
Old 18-02-2010
Member
 
Join Date: Nov 2009
Posts: 446
Re: Replace backslash in a string

Hello,
I have a code with me and i think you guys will be interested to see this
Here is the code:
Code:
 public class Replace  
 {  
    public static void main(String[] args)  
   {  
       String str = "abc";  
      String rep = str.replaceAll("abc", "c:\\\\test\\\\abc");  
       System.out.println(rep);  
    }  
}
Reply With Quote
  #6  
Old 18-02-2010
Member
 
Join Date: Nov 2009
Posts: 333
Re: Replace backslash in a string

Hello,
I think the most important in such programs is to do the loop, what I am saying is this
Code:
loop check:
for (int i=0; i<inputString.length(); i++){
char chval = inputString.charAt(i);
if (chval=='\\'){
return false;
}
}
Hope this will help you.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Replace backslash in a string"
Thread Thread Starter Forum Replies Last Post
Regex replace an integer with string New ID Software Development 5 05-02-2010 12:35 AM
Find and Replace in JavaScript String Wilbur Software Development 5 15-12-2009 01:23 PM
Simple string replace in php cyber-noob Software Development 3 30-11-2009 12:37 PM
Replace backslash with forward slash in Perl _Gentoo_Nile_ Software Development 3 03-08-2009 10:02 PM
Replace a string in multiple files Linux ADISH Tips & Tweaks 0 27-06-2009 10:07 AM


All times are GMT +5.5. The time now is 08:29 AM.