For example.
If i enter "100" in textbox then
messagebox will popup.. "Its a Integer".
or i enter "hello world" then
messagebox will popup "Its a String"..
Etc....
It's hard to outright say... there's some overlap there. Consider the data you enter into a text box is always a string. Any text can be considered a string. Also, some numbers are only doubles... and all floats are doubles, but not all doubles are floats. Same for integers.
So you'll need decide some kind of hierarchy, then just test. For this, you can use the TryParse on most built in value types. You'll just have to start testing, then use else-ifs to check each successive type. Something like this... - double d;
-
float f;
-
integer i;
-
-
if (double.TryParse(stringValue, out d))
-
// string is a double, value in d
-
else if (float.TryParse(stringValue, out f))
-
// string is a float, value in f
-
else if (int.TryParse(stringValue, out i))
-
// string is an int, value in i
-
else
-
// string can't be converted, so it's just text
-
Something like that.
2 3002
string = text
int = numbers
double = numbers separated with a ,
char = one single character like a or c or 1 or 2
It's hard to outright say... there's some overlap there. Consider the data you enter into a text box is always a string. Any text can be considered a string. Also, some numbers are only doubles... and all floats are doubles, but not all doubles are floats. Same for integers.
So you'll need decide some kind of hierarchy, then just test. For this, you can use the TryParse on most built in value types. You'll just have to start testing, then use else-ifs to check each successive type. Something like this... - double d;
-
float f;
-
integer i;
-
-
if (double.TryParse(stringValue, out d))
-
// string is a double, value in d
-
else if (float.TryParse(stringValue, out f))
-
// string is a float, value in f
-
else if (int.TryParse(stringValue, out i))
-
// string is an int, value in i
-
else
-
// string can't be converted, so it's just text
-
Something like that.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Julie |
last post by:
I'm re-evaluating the way that I convert from a std::string to char *.
(Requirement: the source is a std::string, the usable contents are char *)
Here is what I've come up with:
#include...
|
by: karthik.naig |
last post by:
Hi,
This was the routine I wrote earlier to convert a C++ string to a
char array.
But I found that the char* array consisted only of junk after returning
from the below function.
|
by: karthik.naig |
last post by:
Hi,
This was the routine I wrote earlier to convert a C++ string to a
char array.
But I found that the char* array consisted only of junk after returning
from the below function.
int...
|
by: Tim Conner |
last post by:
Hi,
I am an ex-delphi programmer, and I having a real hard time with the
following simple code (example ):
Which is the equivalent to the following code ?
var
chars : PChar;
sBack, s :...
|
by: Yifan |
last post by:
Hi
Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks
Yifan
|
by: Peteroid |
last post by:
How the heck does one convert a String* to char? Specifically:
String* my_string = "HELLO" ;
char m_char_array ;
m_char_array = my_string ; // error
strcpy( m_char_array, my_string ) ; //...
|
by: Frank R Eid |
last post by:
Hi all;
A) What's the simplest way to convert a 'String' to 'char *' (and the other
way araound) ?
B) I have some C++ classes that I cannot easily convert to .NET (because
they still are...
|
by: Alejandro Aleman |
last post by:
Hello!
i know this may be a newbie question, but i need to convert a string from
System::String^ to char*, in the msdn page tells how, but i need to set to
/clr:oldSyntax and i dont want it...
|
by: oll3i |
last post by:
public class Cennik {
private static Cennik instance = null;
Map<String,Double> cennik = new HashMap<String,Double> ();
private Cennik() { // prywatny konstruktor
}
public...
|
by: aarklon |
last post by:
Hi all,
why printf("....%d",sizeof((int)(double)(char) i)) always gives the
size of int ???
is it because sizeof doesn't evaluate its operand....???
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |