Conversion of String to Upper Case Without Inbuilt Methods

Conversion of string to upper case without inbuilt methods

You need to execute ord() for each character of your input string. instead of the input string:

def uppercase(str_data):
return ''.join([chr(ord(char) - 32) for char in str_data if ord(char) >= 65])

print(uppercase('abcdé--#'))
>>> ABCDÉ

Without join:

def uppercase(str_data):
result = ''
for char in str_data:
if ord(char) >= 65:
result += chr(ord(char) - 32)
return result
print(uppercase('abcdé--#λ'))
>>> ABCDÉΛ

How to convert lowercase string to uppercase string without toUppercase() function

function alpha()
{
var a=prompt("Enter String: ");
var output="";
for(var x=0;x<a.length;x++)
output+=String.fromCharCode(a.charCodeAt(x)>96 && a.charCodeAt(x)<123 ? a.charCodeAt(x)-32: a.charCodeAt(x))
return output;
}
console.log("--" + alpha());

Just get the ascii code for each char, and if it ranges between 97 to 122 ( a to z ) deduct 32 from val to get the corresponding upper case char. Hope this helps.

How can i convert to upper case manually ?(Javascript)

Here is a function that does it (very old-school and manual) :

  • Loop through the string
  • If you encounter a lower case character, in other words, if you are at a character whose ASCII code is in the range [97,122], which is the range of the lower case alphabet characters, subtract 32 from it's ASCII code, because the difference between a lower case alpha-char and it's upper case form in ASCII is 32, then add it to a new string.
  • Else, add the character as is.



And as @georg, who is German (German alphabets include accented letters) pointed out, I added an update to include them.

Their range is [224,255], and the difference between each one and its upper-case form is also 32, so, no need for an else if :

function myToUpperCase(str) {  var newStr = '';  for (var i=0;i<str.length;i++) {    var thisCharCode = str[i].charCodeAt(0);    if ((thisCharCode>=97 && thisCharCode<=122)||(thisCharCode>=224 && thisCharCode<=255)) {     newStr += String.fromCharCode(thisCharCode - 32);    } else {     newStr += str[i];    }  }  return newStr;}console.log(myToUpperCase('helLo woRld!')); // => HELLO WORLD!console.log(myToUpperCase('üñïçødê')); // => ÜÑÏÇØDÊ

Java - Convert lower to upper case without using toUppercase()

Looks like homework to me, Just a hint. You are printing string a whereas you are modifying the char type aChar, its not modifying the original string a. (Remember strings are immutable).

How i can Capitalize without using toUpperCase

You can use fromCharCode and charCodeAt to switch between lower and upper letter: