Given a string of text
var string1 = 'IAmNotFoo';
How do you extract just the capital letters?
'IANF'
Here are some methods per links below:
function isUpperCase1(aCharacter) {
if ( ch == ch.toUpperCase() ) {
return true;
}
return false;
}
function isUpperCase2( aCharacter ) {
return ( aCharacter >= 'A' ) && ( aCharacter <= 'Z' );
}
var string1 = 'IAmNotFoo',
string2 = '',
i = 0,
ch = '';
while ( i <= string1.length ) {
ch = string1.charAt( i );
if (!isNaN( ch * 1 ) ) {
alert('character is numeric');
}
else if ( isUpperCase2() ) { // or isUpperCase1
string2 += ch;
}
i++;
}
or simply ( per comment below ):
var upper = str.replace(/[^A-Z]/g, '');
SO Related
Finding uppercase characters within a string
How can I test if a letter in a string is uppercase or lowercase using JavaScript?