For some reason when I run the “test” method, I am getting a false result. I used some of the code from my other question about random number generation, which I have confirmed does work, but with additional safety checks.
public class strUtls
{
public void test()
{
var maybe = 40000000f * 40000000f;
bool number = isNumber(maybe);
}
public bool isNumber(object O)
{
// INT16,INT32,INT64,DOUBLE,FLOAT
if (upper(O.GetType().ToString()).Contains("INT") || upper(O.GetType().ToString()).Contains("DOUBLE") || upper(O.GetType().ToString()).Contains("FLOAT"))
{
return true;
}
else
{
return false;
}
}
private string upper(string s)
{
try
{
for (int i = 0; i < s.Length; i++)
{
s = s.Replace(s[i], upper(s[i]));
}
return s;
}
catch (IndexOutOfRangeException)
{
return s;
}
}
private char upper(char S)
{
switch (s)
{
case ('a'):
return 'A';
break;
case ('b'):
return 'B';
break;
case ('c'):
return 'C';
break;
case ('d'):
return 'D';
break;
case ('e'):
return 'E';
break;
case ('f'):
return 'F';
break;
case ('g'):
return 'G';
break;
case ('h'):
return 'H';
break;
case ('i'):
return 'I';
break;
case ('j'):
return 'J';
break;
case ('k'):
return 'K';
break;
case ('l'):
return 'L';
break;
case ('m'):
return 'M';
break;
case ('n'):
return 'N';
break;
case ('p'):
return 'O';
break;
case ('o'):
return 'P';
break;
case ('q'):
return 'Q';
break;
case ('r'):
return 'R';
break;
case ('s'):
return S;
break;
case ('t'):
return 'T';
break;
case ('u'):
return 'U';
break;
case ('v'):
return 'V';
break;
case ('w'):
return 'W';
break;
case ('x'):
return 'X';
break;
case ('y'):
return 'Y';
break;
case ('z'):
return 'Z';
break;
default:
return s;
break;
}
}
}
Simplifying the madness a little, The easiest way to find your answer is to examine the contents of the string. Others have already outlined the correct approach now. I’m just posting this to give you an idea of a better way to structure the same code. String already has a ToUpper() Method, by the way.