Quantcast
Channel: Embarcadero Community - Embarcadero Community
Viewing all articles
Browse latest Browse all 2504

Odd StrToInt behavior

$
0
0

I'm getting odd behavior with the StrToInt method. (I do have included.)

I read in data from a file using

                   TStringList *mytext = new TStringList;

                   mytext->LoadFromFile("C:/data.txt");

I then fetch a line by

                   String line;

                   line = mytext->Strings[0];

I then select a sequence within 'line' that should represent an integer, in fact the single character '0'.

                   dummy = line.SubString(start, howlong);

But then, the line

                    int n = StrToInt(dummy);

gives the error report " is not a valid integer value

The bizarre thing is that if I test this by setting

                      String dummy2 = "0";

                      bool test1 = (dummy == dummy2);

                      int m = StrToInt(dummy2);

then test1 shows up as 'true', but 'StrToInt(dummy2)' generates no error and assigns 0 to m (!). I don't know how 'test1' can be 'true' and yet have 'StrToInt()' accept 'dummy2' as an input but reject 'dummy' as an input.

Thanks for help.

River_Forest


Viewing all articles
Browse latest Browse all 2504

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>