File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Replacement problem

 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey i have one string lets suppose

now i want to replace ' this with " this
i tried the replace method in the string the parameters are char and we have to write them in the ' ' but when i write ''' getting error please guide me how i can replace this
 
john sal
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use String s1 = s.replace("'", "\""); instead.
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks problem is solved can you provide the explanation why that was not working and why its working?
 
Raymond Tong
Ranch Hand
Posts: 240
2
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akhter wahab wrote:hey i have one string lets suppose

now i want to replace ' this with " this
i tried the replace method in the string the parameters are char and we have to write them in the ' ' but when i write ''' getting error please guide me how i can replace this

You should use escape character \ if you have ' in char and " in string.
 
Raymond Tong
Ranch Hand
Posts: 240
2
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akhter wahab wrote:thanks problem is solved can you provide the explanation why that was not working and why its working?

you have to surround your char with single quotes
and your String with double quotes

In your case, ''' (3 single quotes)
1st single quote treated as starting enclosure of your char
2nd single quote treated as ending ...
3rd single quote treated as starting ...

You would end up having syntax error.

If you want to have ' in char and " in String, you have to use \ as escape character telling your editor / compiler it is not the enclosure.
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now i have one more problem regarding replacement


i have to convert the String v into the integer then how i can remove the Comma from 10000
 
Virendrasinh Gohil
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akhter wahab wrote:now i have one more problem regarding replacement
i have to convert the String v into the integer then how i can remove the Comma from 10000


This problem is due to typo. Seems like you replace ' instead of comma.
Try this.
 
akhter wahab
Ranch Hand
Posts: 151
Java MyEclipse IDE Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohhh my GOD what a blunder i was doing ehehehehhehehheheh and i was trying this from last half hour
 
Virendrasinh Gohil
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
akhter wahab wrote:ohhh my GOD what a blunder i was doing ehehehehhehehheheh and i was trying this from last half hour


All human make mistakes. This proves that you are a human.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic