+ 2

How to find an input which is not a DataType?

I'm getting an user input from user, Since if they type 2 means it will print integer, for 13.2 it will print float, for true it will print bool and for "name" it will print string, Now if they type %& likee that symbols means it will output not datatype, how should I Do that? https://code.sololearn.com/ca13A20A12A1/?ref=app

1st Mar 2021, 10:12 AM
Gouse Basha
Gouse Basha - avatar
3 Answers
+ 2
This is a tricky one, there is a lot that can be a string. %& is technically a string The discount is 5% is a valid string The brown fox and lots of other words are a string. Have a look at Char.IsSymbol method and there are lots of other Char.Is...... methods https://docs.microsoft.com/en-us/dotnet/api/system.char.issymbol?view=net-5.0 https://www.tutorialspoint.com/char-issymbol-method-in-chash https://www.geeksforgeeks.org/c-sharp-char-issymbol-method/ https://csharp.net-tutorials.com/data-types/the-char-type/ know that you can iterated through a string with string input = "hello"; foreach(char c in input) { if (Char.IsSymbol(c)) { Console.WriteLIne("char is symbol"); } else { Console.WriteLIne("char is not a symbol"); } }
1st Mar 2021, 12:57 PM
sneeze
sneeze - avatar
+ 2
sneeze if I write else means it will not print "string" since I have given final ="string" at top and if condition as if(!string.IsNullOrEmpty(o)){ .... }
1st Mar 2021, 10:47 AM
Gouse Basha
Gouse Basha - avatar
+ 1
if () // one statement { } else if() // as many as you like, even no else if is allowed { } else //one statement, or no else at all { } you can write else { final = "not datatype"; }
1st Mar 2021, 10:31 AM
sneeze
sneeze - avatar