hi.. i have a question regarding Swapping of characters in a string that uses stringbuffer.. like StringBuffer codestring="abcdefghijkl"..how do i swap the char 'a' with 'd' in the string so that final string is like.. codestring="dbcaefghijkl"..
This will only replace 'a' to 'd' not the 'd' to 'a'. He might want to replace these 2 chars simultaneously.
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
posted
0
This will only replace 'a' to 'd' not the 'd' to 'a'. He might want to replace these 2 chars simultaneously.
Hi Ankur
i just seen how do i swap the char 'a' with 'd' in the string this sentence.Poster doesnot say about vice versa.If he/she wants wants then we will come with some other solution.
how do i swap the char 'a' with 'd' in the string this sentence.Poster does not say about vice versa
I'm not a native English-speaker, but I think swap is not the same as replace, which is what you are referring to. Swap indeed means that the two items in questions switch their places, so there really is no "vice versa" - both happen at the same time.
One possibility would be to replace 'a' by a completey different character -which you can be sure does not otherwise occur in the string-, then replace 'd' by 'a', and then the other character by 'd'.
Here's a replace based on REXX syntax. Note how it can be used to rearrange a string. You could use that to swap characters based on position. I bet it would not give correct results on translate AD to DA.
This is very old code with a semi-hungarian prefix naming thing that I outgrew ...
The left() method pads or truncates as necessary to left justify.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi