wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes String Replacement problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Replacement problem" Watch "String Replacement problem" New topic
Author

String Replacement problem

akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

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


Start Earning Online||Start Earning Using Java
john sal
Ranch Hand

Joined: Jul 30, 2010
Posts: 93
Use String s1 = s.replace("'", "\""); instead.
akhter wahab
Ranch Hand

Joined: Mar 02, 2009
Posts: 151

thanks problem is solved can you provide the explanation why that was not working and why its working?
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

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

Joined: Aug 15, 2010
Posts: 230
    
    2

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

Joined: Mar 02, 2009
Posts: 151

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

Joined: Jun 09, 2004
Posts: 46
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

Joined: Mar 02, 2009
Posts: 151

ohhh my GOD what a blunder i was doing ehehehehhehehheheh and i was trying this from last half hour
Virendrasinh Gohil
Ranch Hand

Joined: Jun 09, 2004
Posts: 46
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Replacement problem