shweta pandit wrote:i hava a string with lowercase and uppercase letters how can i convert the lowercase letters into uppercase and viceversa.please reply soon
thanks in advance...........
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
shweta pandit wrote:
i hava a string with lowercase and uppercase letters how can i convert the lowercase letters into uppercase and viceversa.please reply soon
thanks in advance...........
shweta pandit wrote:problem is not solved please reply....
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here

No, it doesn’t I am afraid.Prashant He wrote: . . . Hope this helps.
Prashant He wrote:The following solution works fine
![]()
Roel De Nijs wrote:Using Character.isLowerCase and Character.isUpperCase is a huge improvement. But what about a String with 10 characters?
R. Jain wrote:And yes this is not a good way, but what else can be done??
Any Idea??
R. Jain wrote:
Roel De Nijs wrote:Using Character.isLowerCase and Character.isUpperCase is a huge improvement. But what about a String with 10 characters?
Well, as far as I know, there is nothing available in String class to handle such a problem(As of today).. One has no other choice rather than to handle this one..
And yes this is not a good way, but what else can be done??
Any Idea??
R. Jain wrote:A better way to do this can be (By Toggling each character) : -
1). Convert the String into byteArray..
2). Iterate over byteArray and for each element do an XOR with 32
3).Create new byteArray with new element..[Edit: Update the existing byteArray with toggled element]
4). byteArray back to String..
R. Jain wrote:
R. Jain wrote:
Roel De Nijs wrote:Using Character.isLowerCase and Character.isUpperCase is a huge improvement. But what about a String with 10 characters?
Well, as far as I know, there is nothing available in String class to handle such a problem(As of today).. One has no other choice rather than to handle this one..
And yes this is not a good way, but what else can be done??
Any Idea??
A better way to do this can be (By Toggling each character) : -
1). Convert the String into byteArray..
2). Iterate over byteArray and for each element do an XOR with 32
3).Create new byteArray with new element..[Edit: Update the existing byteArray with toggled element]
4). byteArray back to String..
Roel De Nijs wrote:
because it might be slightly more performant, but bit twiddling is harder to read and maintain than a simple Character.toUpperCase(c)
R. Jain wrote:Can be better trade-off than that character array.. Where you need to use an extra if-else to check for each character and convert them accordingly.
R. Jain wrote: That if will also be needed when you consider only alphabetic characters in char array too... I'm sure you don't want to do a toLowerCase on a space...
Roel De Nijs wrote:
R. Jain wrote: That if will also be needed when you consider only alphabetic characters in char array too... I'm sure you don't want to do a toLowerCase on a space...
Invoking toLowerCase on a space will return a space, so you don't need an if for that one. You do need an if to invert the character case (upper to lower, lower to upper)
R. Jain wrote:And there wins the toCharArray
![]()
Roel De Nijs wrote:
swapCase("Oops... I didn't try that.") returns oOPS... i DIDN'T TRY THAT.
Thank you for noticing. I would, however, leave that post, because it is a poor solution, and discussing its shortcomings will allow everybody to learn.R. Jain wrote: . . . Prashant, read the Campbell's last post.. This wouldn't help as you are posting direct answers..
We don't do it here.. We are NotACodeMill
Roel De Nijs wrote:
R. Jain wrote:A better way to do this can be (By Toggling each character) : -
1). Convert the String into byteArray..
2). Iterate over byteArray and for each element do an XOR with 32
3).Create new byteArray with new element..[Edit: Update the existing byteArray with toggled element]
4). byteArray back to String..
That depends on your understanding of "better" (more performant, more maintainable,...). I would definitely not opt for this solution, because it might be slightly more performant, but bit twiddling is harder to read and maintain than a simple Character.toUpperCase(c)
| Don't get me started about those stupid light bulbs. |